使用 Meteor 在 Twitter 中使用应用程序发推文
Tweet using application in Twitter with Meteor
我成功地通过仅应用程序身份验证授权了一个请求。但是当我尝试 post 一条带有 REST API 的推文时。该错误与无法访问 post 推文有关。因此,我进行了一项研究,发现 Twitter 不允许对 post 推文进行仅应用程序身份验证。
"And it will not be able to: Post Tweets or other resources;"
但是我找到了"Your access token"区域。我可以用它来 post 推特吗?我该如何使用它?
我也可以用同样的方法评论吗?
到目前为止,这是我的代码,
HTTP.call('POST', 'https://api.twitter.com/oauth2/token', {
params: { 'grant_type':'client_credentials'},
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Authorization': 'Basic '+base64token
}
},function (error, response) {
if (!error && response.statusCode == 200) {
token = response.data.access_token;
HTTP.call('POST', 'https://api.twitter.com/1.1/statuses/update.json', {
params: { 'status':data.tweet},
headers: {
'Authorization': 'Bearer '+token
}
},function (error, response) {
if (!error && response.statusCode == 200) {
console.log(response);
} else {
console.error(error.message);
}
});
} else {
console.error(error.message);
}
});
如果您甚至不说您是 运行 客户端还是服务器端的代码,就很难告诉您具体的事情。
但是如果你在服务器端调用 Twitter API(你应该避免泄露凭据)那么你应该使用许多专门的模块之一与 Twitter API 在 npm 上可用。有关示例,请参阅此答案:
- Node.js Twitter Client
使用正确的工具完成工作比自己重新实现要容易得多,尤其是当您自己做起来有困难时,这里显然就是这种情况。
我成功地通过仅应用程序身份验证授权了一个请求。但是当我尝试 post 一条带有 REST API 的推文时。该错误与无法访问 post 推文有关。因此,我进行了一项研究,发现 Twitter 不允许对 post 推文进行仅应用程序身份验证。
"And it will not be able to: Post Tweets or other resources;"
但是我找到了"Your access token"区域。我可以用它来 post 推特吗?我该如何使用它?
我也可以用同样的方法评论吗?
到目前为止,这是我的代码,
HTTP.call('POST', 'https://api.twitter.com/oauth2/token', {
params: { 'grant_type':'client_credentials'},
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Authorization': 'Basic '+base64token
}
},function (error, response) {
if (!error && response.statusCode == 200) {
token = response.data.access_token;
HTTP.call('POST', 'https://api.twitter.com/1.1/statuses/update.json', {
params: { 'status':data.tweet},
headers: {
'Authorization': 'Bearer '+token
}
},function (error, response) {
if (!error && response.statusCode == 200) {
console.log(response);
} else {
console.error(error.message);
}
});
} else {
console.error(error.message);
}
});
如果您甚至不说您是 运行 客户端还是服务器端的代码,就很难告诉您具体的事情。
但是如果你在服务器端调用 Twitter API(你应该避免泄露凭据)那么你应该使用许多专门的模块之一与 Twitter API 在 npm 上可用。有关示例,请参阅此答案:
- Node.js Twitter Client
使用正确的工具完成工作比自己重新实现要容易得多,尤其是当您自己做起来有困难时,这里显然就是这种情况。