Tessel's First Tweet

Now that you're connected to Wifi, let's try a tweet!

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

If you want 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.

First, create a new directory within your "tessel-code" directory:mkdir tessel-tweetcd tessel-tweetnpm init

Now copy and paste the following into a new file and save it as "tweet.js". Change the twitterHandle var to your own Twitter handle.

// Node requires
var twitter = require('twitter');
var util = require('util')

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

// Enter the oauth key and secret information
var twit = new twitter({
  consumer_key: 'O7oc0pvsZn4xjgcuHuYdX4FaC',
  consumer_secret: 'iJYuHFz2sD46Nvk3mcwzX8uih14aEAMgVWdWoR59nx8v6Zl7ZX',
  access_token_key: '2529232909-luARGU89K4CKFMvfzBjCgG6ubefzDkdDWkSB85i',
  access_token_secret: 'GXQfuzvGdjLEs3t1HEYfhQ9x9bdBcSBVXjBkbRgwYlOE0'

// Make a tweet!
twit.updateStatus(status, function(data) {
  if (data.name === 'Error') {
    console.log('error sending tweet!', data.message);
  else {
    console.log('tweet successful!');

We're using the twitter Node.js library for convenience

We'll need to install the library using npm:npm install twitter

Now runtessel run tweet.js

Check Twitter for your tweet!

Bonus: Try making Tessel tweet output from a module.

Fork on Github