我正在尝试与Tumblr API交互以获取关注者列表。我是整个OAuth的新手,所以我尝试通过https://adodson.com/hello.js/demos/tumblr.html上的演示对电话进行建模。不幸的是,他们给出的示例仅需要用于识别的API密钥(https://www.tumblr.com/docs/en/api/v2#posts),在获取跟随者时,需要经过签名的OAuth请求(https:// www .tumblr.com / docs / en / api / v2#followers)。
我正在使用的电话是:
function getFollowers(blog){
hello('tumblr').api('blog/'+blog+'/followers/').then(function(r){
console.log("r", r);
//Bellow here not really relevant
var a = r.data.map(function(item){
return "<h2>"+item.title+"</h2>"+item.body_abstract;
});
document.getElementById('blogs').innerHTML = a.join('');
});
}
这将从代理生成请求URL:
https://auth-server.herokuapp.com/proxy?path=https%3A%2F%2Fapi.tumblr.com%2Fv2%2Fblog%2Fnmlapp.tumblr.com%2Ffollowers%2F%3Fapi_key%3DREDACTED08u%26callback%3D_hellojs_9kvqxi31&access_token=&then=redirect&method=get&suppress_response_codes=truee
和Tumblr的API返回
_hellojs_9kvqxi31({"meta":{"status":401,"msg":"Not Authorized"},"response":[]});
我可以看到该登录调用在“查询字符串参数”字段中具有所有OAuth信息,而我尝试创建的却没有,但是我不确定通过helloJS包含哪种正确的方法。
知道了,该功能必须包装在login方法中。这在另一个示例中得到了展示,但是它从api对象中调用参数的方式使我感到困惑。
function doTheThing(network){
hello( network ).login({force:false}).then( function(r){
hello('tumblr').api('followers').then(function(r){
console.log("r", r);
var a = r.data.map(function(item){
return "<h2>"+item.title+"</h2>"+item.body_abstract;
});
document.getElementById('blogs').innerHTML = a.join('');
});
});
}
//...
tumblr:{
get: {
//...
//This next part needs to be generated dynamically, but you get the idea
'followers': 'blog/BLOGNAME.tumblr.com/followers',
}
callback(p.path);
}
},
post: {
//...
'followers': function(p, callback) {
p.path = 'followers';
query(p, callback);
}
},
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句