javascript - 用xauth认证获取到的AccessToken请求api不成功
本文介绍了javascript - 用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;
解决方案
终于发现哪里错了
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
这篇关于javascript - 用xauth认证获取到的AccessToken请求api不成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文