我正在使用Meteor和Twitter API进行项目。我想从Twitter获取用户信息。我编写了一个函数,例如仅从Twitter返回用户的位置。我相信这是对流星提出请求的正确方法。它是:使用Twitter API的Meteor.http.get问题
Meteor.methods({getTwitterLocation: function (username) {
Meteor.http.get("https://api.twitter.com/1/users/show.json?screen_name="+ username +"&include_entities=true", function(error, result) {
if (result.statusCode === 200) {
var respJson = JSON.parse(result.content);
console.log(respJson.location);
console.log("location works");
return (respJson.location)
}else {
return ("Unknown user ")
}
});
}});
现在这个函数会记录我的Git Bash中的控制台上的内容。我通过做Meteor.call得到someones位置。但我想发布那个函数在页面上返回的内容。就我而言,我想在用户的个人资料中张贴。这不起作用。但console.log(respJson.location)返回我的Git Bash中的位置,但它不会在配置文件页面上显示任何内容。这是我做了我的个人资料页上:
profile.js:
Template.profile.getLocation= function(){
return Meteor.call("getTwitterLocation","BillGates");
}
profile.html:
<template name="profile">
from {{getLocation}}
</template>
有了,我得到的 “西雅图” 和““位置的作品“在我的Git Bash上,但在配置文件页面上没有任何内容,如果有人知道我可以做什么,那将会非常感激,谢谢
嘿,非常感谢你,工作! :) – moni 2013-05-18 02:53:58
啊,但你知道为什么有时它有效,有时它说错误? – moni 2013-05-18 03:16:34
这可能是twitter向1.1 api的迁移和旧api的折旧。查看更新后的帖子 – Akshat 2013-05-18 09:21:34