用xauth认证获取到的AccessToken请求api不成功

用的是这里的开源项目https://github.com/Mashape/ma...
应该是这一步出错了

oa.post(options, callback);
oa.get(options, callback);
oa.delete(options, callback);
oa.patch(options, callback);
oa.put(options, callback);

// Alternatively, you can use the old node-oauth style: (Where method is one of five above.)
oa.method(url, oauth_token, oauth_token_secret, body, type, parameters, callback);

获取到了acess_token,但是调取api的时候报错"error":"Invalid access token",求大神帮忙看一下 感激不尽

var express = require('express');
    var router = express.Router();
    var OAuth = require('mashape-oauth').OAuth;
    var consumerKey    = 'myconsumerKey';
    var consumerSecret = 'myconsumerSecret';
    var oa = new OAuth({ 
      accessUrl:"http://fanfou.com/oauth/request_token",
      consumerKey:consumerKey,
      consumerSecret:consumerSecret,
      version:'1.0',
      signatureMethod:'HMAC-SHA1'
    });
    
    /* GET home page. */
    router.get('/', function(req, res, next) {
      res.render('index', { title: 'hello' });
    });
    router.route("/fanfou").get(function(req,res){   
        res.render("fanfou",{title:'fanfou'});
    }).post(function(req,res){                        
        var username = req.body.username;  
        var password= req.body.password;
        oa.getXAuthAccessToken(username, password, function (error, oauth_token, oauth_token_secret, results) {
          if (error)
            console.log('err');
          else
          {
          /* res.json({
            oauth_token:oauth_token,
            oauth_token_secret:oauth_token_secret
           })*/
           oa.get('http://api.fanfou.com/statuses/home_timeline.json',
           oauth_token,oauth_token_secret,null,null,null,function(error,data){
                   res.json({
                     data:data
                   });
                   //console.log(JSON.parse(data));
           }); 
          }
    
        });
      
    });
    module.exports = router;
阅读 3.8k
2 个回答

终于发现哪里错了

var oa = new OAuth({ 
      accessUrl:"http://fanfou.com/oauth/request_token",
      consumerKey:consumerKey,
      consumerSecret:consumerSecret,
      version:'1.0',
      signatureMethod:'HMAC-SHA1'
    });

这里面的 accessUrl填错了,应该是http://fanfou.com/oauth/access_token

你是用的是 getXAuthAccessToken 获得的 XAuth 认证的 Token,然后把凭证交给了 OAuth 的方法,肯定错了啊

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题