bartve / disconnect

An easy to use Node.js client with OAuth support to connect with the discogs.com API v2.0
MIT License
453 stars 79 forks source link

Cannot access to my data w/ OAuth or userToken #56

Closed kolorfilm closed 5 years ago

kolorfilm commented 5 years ago

I try to connect to my inventory but everytime I get zero items.

const express = require('express');
const storage = require('node-persist');
const bodyParser = require('body-parser');
const Discogs = require('disconnect').Client;
const app = express();

storage.init();

app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));
app.set('view engine', 'ejs');

app.get('/', function (req, res) {
  res.render('index');
});

app.get('/authorize', function(req, res){
  var oAuth = new Discogs().oauth();
  oAuth.getRequestToken(
    'myconsumerKey',
    'myconsumerSecret',
    'http://localhost:8080/callback',
    function(err, requestData){
      storage.setItem('requestData', requestData);
      res.redirect(requestData.authorizeUrl);
    }
  );
});

app.get('/callback', function(req, res){
  storage.getItem('requestData').then((requestData) => {
    var oAuth = new Discogs(requestData).oauth();
    oAuth.getAccessToken(
      req.query.oauth_verifier,
      function(err, accessData){
        storage.setItem('accessData', accessData);
        res.redirect('/identity');
      }
    );
  });
});

app.get('/identity', function(req, res){
  storage.getItem('accessData').then((accessData) => {
    var dis = new Discogs(accessData);
    dis.getIdentity(function(err, data){
      res.send(data);
    });
  });
});

app.get('/inventory', function(req, res){
  storage.getItem('accessData').then((accessData) => {
    var col = new Discogs(accessData).user().getInventory();
    col.then((a) => {
      console.log(a);
    });
  });
});

app.listen(8080, function () {
  console.log('Example app listening on port 8080!');
});

The output in "inventory" method is just.:

{ pagination: { per_page: 50, items: 0, page: 1, urls: {}, pages: 1 }, listings: [] }

0 items. Also when I try to show my profile, the urls are missing my username. There is just "undefined" in the link. It would look like this.:

app.get('/profile', function(req, res){
  storage.getItem('accessData').then((accessData) => {
    var profile = new Discogs(accessData).user().getProfile();
    profile.then((a) => {
      console.log(a);
    });
  });
});

The output is:

{ profile: '',
  banner_url: '',
  wantlist_url: 'https://api.discogs.com/users/undefined/wants',
  seller_num_ratings: 0,
  rank: 4,
  is_staff: false,
  num_pending: 1,
  id: 1032059,
  marketplace_suspended: false,
  buyer_rating: 0,
  num_for_sale: 0,
  home_page: '',
  location: '',
  collection_folders_url: 'https://api.discogs.com/users/undefined/collection/folders',
  username: 'undefined',
  collection_fields_url: 'https://api.discogs.com/users/undefined/collection/fields',
  releases_contributed: 1,
  activated: true,
  registered: '2011-02-11T13:18:35-08:00',
  rating_avg: 5,
  num_collection: 1,
  releases_rated: 1,
  curr_abbr: 'EUR',
  seller_rating_stars: 0,
  num_lists: 0,
  name: '',
  buyer_rating_stars: 0,
  num_wantlist: 0,
  inventory_url: 'https://api.discogs.com/users/undefined/inventory',
  uri: 'https://www.discogs.com/user/undefined',
  buyer_num_ratings: 0,
  avatar_url:
   'https://secure.gravatar.com/avatar/ee0787acbde96eba8f230d13c0e798e9?s=500&r=pg&d=mm',
  resource_url: 'https://api.discogs.com/users/undefined',
  seller_rating: 0 }

You see a lot of "undefined" values in the urls. What I'm doing wrong?

bartve commented 5 years ago

When you look at the user.getInventory() function in user.js you'll see that it needs a username as the first argument. Same for user.getProfile().

kolorfilm commented 5 years ago

When you look at the user.getInventory() function in user.js you'll see that it needs a username as the first argument. Same for user.getProfile().

Ah ok I see. Thanks! It is working now. :-)