プロジェクトに Meteor と Twitter API を使用しています。Twitterからユーザーの情報を取得したい。たとえば、Twitter からユーザーの場所のみを返す関数を作成しました。これが Meteor でリクエストを行う適切な方法だと思います。ここにあります :
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 を実行して、誰かの位置情報を取得します。しかし、その関数が返すものをページに投稿したいと思います。私の場合、ユーザーのプロフィールに投稿したいと考えています。これはうまくいきません。しかし、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 に「Seattle, WA」と「"location works" が表示されますが、プロファイル ページには何も表示されません。誰かが私に何ができるかを知っていれば、本当に感謝しています。ありがとう。