I am successful in authorizing a request with application-only authentication. But when I tried to post a tweet with REST API. The error is related to not having an access to post a tweet. So I do a research and found out that Twitter doesn't allow app-only authentication to post tweets.
"And it will not be able to: Post Tweets or other resources;"
But I found the "Your access token" area. Can I use it to post tweet? How can I use it?
Also can I use the same method for commenting?
Here is my code so far,
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);
}
});
via JMA
No comments:
Post a Comment