How do I make a Tweet in Zapier code

心已入冬 提交于 2019-12-02 08:51:17

问题


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:

  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!



来源:https://stackoverflow.com/questions/38624607/how-do-i-make-a-tweet-in-zapier-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!