用的是这里的开源项目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;
终于发现哪里错了
这里面的 accessUrl填错了,应该是
http://fanfou.com/oauth/access_token