Skip to content

Latest commit

 

History

History
96 lines (68 loc) · 3.1 KB

tweet.md

File metadata and controls

96 lines (68 loc) · 3.1 KB

{::options parse_block_html="true" /}

Tessel's First Tweet

Because Tessel runs Node, we can leverage the thousands of libraries that the Node community has made.

This code snippet makes Tessel send a tweet from a dummy account (@TesselTweet) that we've created for this purpose.

_If you would prefer to post from your own account, go to apps.twitter.com, create your own OAuth tokens with read and write permissions, and paste them into the script._


Create a new directory within your "tessel-code" directory:

mkdir tessel-tweet; cd tessel-tweet; t2 init

Use npm to install the Twitter library that the Node.js community has built:

npm install twitter

Rename the "index.js" file you've just created to "tweet.js", then copy and paste the below script over the existing text:

{% highlight javascript %} // Node requires var twitter = require('twitter');

var twitterHandle = '@tesselproject'; // The status to tweet var status = 'Hello ' + twitterHandle + '. This is your #Tessel 2 speaking.';

// These OAuth credentials are for the dummy @TesselTweet account // Paste in your own OAuth details if you want to tweet from your own account var twit = new twitter({ consumer_key: 'O7oc0pvsZn4xjgcuHuYdX4FaC', consumer_secret: 'iJYuHFz2sD46Nvk3mcwzX8uih14aEAMgVWdWoR59nx8v6Zl7ZX', access_token_key: '2529232909-luARGU89K4CKFMvfzBjCgG6ubefzDkdDWkSB85i', access_token_secret: 'GXQfuzvGdjLEs3t1HEYfhQ9x9bdBcSBVXjBkbRgwYlOE0' });

// Make a tweet! twit.post('statuses/update', {status: status}, function(error, tweet, response){ if (error) { console.log('error sending tweet:', error); } else { console.log('Successfully tweeted! Tweet text:', tweet.text); } }); {% endhighlight %}

Change the "twitterHandle" var to your own Twitter handle and save.

Make sure you're [connected to Wifi]({{ site.baseurl }}/wifi.html), then run:

t2 run tweet.js

Check Twitter for your tweet!


Bonus: Try making Tessel tweet output from a module.

Extra bonus: What's another Node module you can try out? Maybe Twilio, PubNub, Plotly, Firebase? Surf around on npm until you find a Node library you like, then try using it with Tessel.