我正在尝试使用 Meteor 构建一个应用程序,该应用程序涉及用户使用 Twitter、Facebook 或 Google+ 登录,然后从应用程序中向这些帐户发布内容。
首先,我试图让 Twitter 正常工作。我的 Twitter 登录正常,并获得了代表他们发推文的权限,但我如何实际发送推文?
我想我需要这个:https://dev.twitter.com/docs/api/1.1/post/statuses/update但我无法弄清楚身份验证如何与 Meteor 一起工作。
有什么例子可以帮助我吗?还是教程?
最佳答案
除非您想使用 REST 和 Meteor.http
手动完成,否则您需要一个 API 来帮助您。我建议你得到陨石:https://github.com/oortcloud/meteorite
它像节点模块一样通过 npm install -g meteorite
安装
Meteorite 是 meteor 的包装器,可让您使用 http://atmosphere.meteor.com 上的社区包
您可以使用的 twitter 包是 twitter-api
,通过 mrt add twitter-api
安装:https://github.com/Sewdn/meteor-twitter-api
使用服务器 API 添加后,您可以通过以下方式添加推文:
服务器 JS
var twitter = new Twitter();
Meteor.methods({
postTweet: function (text) {
if(Meteor.user())
twitter.postTweet(text),
return true;
}
});
客户端 JS
//Use this in your click handler where you want to post a tweet:
Meteor.call("postTweet", "This is Twweeeeeetttt!", function(err,result) {
if(!err) {
alert("Tweet posted");
}
});
api 负责处理用户的 oauth token ,因此您不必太担心
关于api - 从 meteor 应用程序中发推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15772951/