我一直有这个问题。好像它有效一段时间然后没有太多的押韵或理由就打破了它。
router.get('/home/', function(req, res, next) {
var code = req.query.code;
console.log("acquired code from SC");
req.SC.authorize(code, function(err, accessToken) {
if ( err ) {
throw err;
} else {
console.log("traded code for access token");
req.session.oauth_token = accessToken;
// Client is now authorized and able to make API calls
//res.render('home', { token: accessToken });
soundcloud.getLoggedInUser(accessToken, function(user){
console.log("done getting user from SC");
});
}
});
});
这是getLoggedInUser函数。
//get data for the user who is logged in
function getLoggedInUser(accessToken, done){
var href = 'https://api.soundcloud.com/me?oauth_token=' + accessToken;
getRequest(href, done);
}
//used for get requests to soundcloud API
function getRequest(href, done){
console.log(href);
requestify.get(href).then(function(response){
console.log(done);
done(response.getBody());
});
}
这是输出。
acquired code from SC
traded code for access token
https://api.soundcloud.com/me?oauth_token=
[Function]
我猜这是我的节点/快速设置的问题,而不是这个代码本身的问题。有什么想法吗?