Twitter | Tweet & Delete Tweets
Post Tweets to your Twitter account
The Twitter block allows you to access Twitter's REST API through PubNub. You can Tweet, delete Tweets, and more from an authorized Twitter account by publishing a PubNub message. This can power apps like Twitter bots or a Delight Engine connection for a PubNub Open Growth instance.
Walkthrough
Create a Twitter application on https://apps.twitter.com/, grant it access to a Twitter account, and give it Read and Write permission. Next, go to the Twitter application's Keys and Access Tokens page to retrieve the access token, key, and secrets. Enter them into a PubNub Twitter block event handler; they are declared near the top.
//Enter your Twitter app's keys and tokens here. Don't share them with anyone! const consumerKey = ""; const consumerSecret = ""; const accessToken = ""; const oauthTokenSecret = "";
To post a Tweet, publish a PubNub message to the block's channel like this:
{ "tweet": "My tweet via PubNub BLOCKS. #PubNub" }
To delete a Tweet, publish a message like this:
{ "delete": true, "id": "ID of Tweet to delete" }
A Tweet's specific ID number is exposed in the response from Twitter's REST API when you post or delete a Tweet. The ID is stored in the response body's id_str
property.
Input
Publish message containing the Tweet body to input channel. Input Channel: twitter-input
1