Twitter sample
Using the twitter sample bundle
The Twitter timeline bundle retrieves some of the latest tweets from skate702 and printing them to your console.
Prerequisites
- Working NodeCG & nodecg-io installation
- An app and their following keys and tokens
- The API key here oauthConsumerKey
- The API secret key here oauthConsumerSecret
- The Access token here oauthToken
- The Access token secret here oauthTokenSecret
Note: You will need a twitter developer account (https://developer.twitter.com/en/apply-for-access) to get the necessary keys and tokens.
Configure the sample bundle
-
Start nodecg with nodecg-io installed. The twitter-timeline bundle is currently part of it so it should also be loaded.
-
Go to the
nodecg-iotab in the nodecg dashboard. -
Login using your password. If this is your first run, then enter the password with which you want to encrypt your configurations and credentials.
-
Create a new twitter service instance using the left upper menu.
-
Enter credentials for twitter.
The created instance should be automatically selected, if not select it in the upper left menu. Enter your Twitter keys and tokens in monaco (the text-editor on the right) in this format:
{ "oauthConsumerKey": "<API key>", "oauthConsumerSecret": "<API secret key>", "oauthToken": "<Access token>", "oauthTokenSecret": "<Access token secret>" }After entering it, click save.
Note: If you don't see monaco on the right, try reloading the page.
-
Set the created twitter service instance to the service dependency of the twitter-timeline bundle.
Select the twitter-timeline bundle and the twitter service in the left bottom menu and then select the service instance that should be used by the twitter-timeline bundle (in this case the name of the previously created twitter instance).
-
Check the nodecg logs
You should see an error or a success message and up to 50 Twitter messages tweeted by the user that is hardcoded in samples/twitter-timeline/extension/index.ts as
screen_name.
Need to know for creating your own twitter bundle
A little description of the twitter client and it's usage
-
The client implements the different API endpoints with two functions
client.get("<get endpoint name>", params, callback) client.post("<post endpoint name>", params, callback) // Instead of callbacks it can be used with promises client .get("statuses/user_timeline", {screen_name: "skate702"}) .then((tweets) => /* Do something with the tweets */) .catch((error) => /* Handle error */); // Or async and await as well try { const tweets = await client.get("statuses/user_timeline", {screen_name: "skate702"}); // Do something with the tweets } catch (error) { // Handle error }