Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我使用AccessToken请求我网站的API时,得到一个错误,即';无效的访问令牌';_Javascript_Node.js_Api_Express_Oauth - Fatal编程技术网

Javascript 当我使用AccessToken请求我网站的API时,得到一个错误,即';无效的访问令牌';

Javascript 当我使用AccessToken请求我网站的API时,得到一个错误,即';无效的访问令牌';,javascript,node.js,api,express,oauth,Javascript,Node.js,Api,Express,Oauth,我曾经获取AccessToken,但是当我使用AccessToken请求我的网站的API时,得到了一个错误,即“无效访问令牌”。 可能我在这一步中出错了,这是由mashape oauth提供的: oa.post(options, callback); oa.get(options, callback); oa.delete(options, callback); oa.patch(options, callback); oa.put(options, callback); // Alterna

我曾经获取AccessToken,但是当我使用AccessToken请求我的网站的API时,得到了一个错误,即“无效访问令牌”。 可能我在这一步中出错了,这是由mashape oauth提供的:

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);
我应该如何更改代码以请求API? 以下是我的尝试:

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;