How do I make a Tweet in Zapier code

2019-03-02 18:44发布

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条回答
闹够了就滚
2楼-- · 2019-03-02 19:00

This is fairly straightforward if you know the incantations:

  1. Get a token from https://dev.twitter.com/oauth/overview/application-owner-access-tokens.
  2. Add a Authorization: Bearer <yourtoken> header to your fetch() call.

And you should be good to go!

查看更多
登录 后发表回答