问题
The following does not work in the "Code by Zapier" Action.
fetch('https://api.twitter.com/1.1/statuses/update.json?status=' +encodeURIComponent(textToTweet))
.then(function(res) {
return res.json();
})
.then(function(json) {
callback(null, json);
})
.catch(callback);
However, I get the following.
errors:
message:
Bad Authentication data.
code:
215
What additional authentication does one need to do? The Twitter account is already connected to Zapier, or does that not matter?
UPDATE: per feedback below the following code now gives me an 89: invalid or expired token
fetch('https://api.twitter.com/1.1/statuses/update.json?status=' +encodeURIComponent(textToTweet), {
headers: {
Authorization: 'Bearer ACCESS_TOKEN_BEGINSWITH_OWNERID'
}
})
.then...............
回答1:
This is fairly straightforward if you know the incantations:
- Get a token from https://dev.twitter.com/oauth/overview/application-owner-access-tokens.
- Add a
Authorization: Bearer <yourtoken>
header to yourfetch()
call.
And you should be good to go!
来源:https://stackoverflow.com/questions/38624607/how-do-i-make-a-tweet-in-zapier-code