diff --git a/tweet.html b/tweet.html index 8630f43..24206bb 100644 --- a/tweet.html +++ b/tweet.html @@ -2,89 +2,7 @@ layout: default --- -

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.

- -
- -
-
- Prev: - Wifi -
-
- Next: Usage -
-
+{% capture include_install %} +{% include_relative tweet.md %} +{% endcapture %} +{{ include_install | markdownify }} diff --git a/tweet.md b/tweet.md new file mode 100644 index 0000000..e821b41 --- /dev/null +++ b/tweet.md @@ -0,0 +1,95 @@ +{::options parse_block_html="true" /} + +
+
+ +# Tessel's First Tweet + +Make sure you're [connected to Wifi]({{ site.baseurl }}/wifi.html), then 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-tweet; cd tessel-tweet; t2 init` + +Rename the "index.js" file you've just created to "tweet.js": + +`mv index.js tweet.js` + +Now open "tweet.js". Copy and paste the below script over the existing text: + +{% highlight javascript %} +// Node requires +var twitter = require('twitter'); + +var twitterHandle = '@technicalhumans'; +// The status to tweet +var status = 'Hello ' + twitterHandle + '. This is your #Tessel 2 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.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. + +We're using the [Node.JS twitter library](https://www.npmjs.org/package/twitter). Install it using npm: + +`npm install twitter` + +
+
+ +
+
+ +Now run: + +`t2 run tweet.js` + +Check Twitter for your tweet! + +
+
+ +![](https://s3.amazonaws.com/technicalmachine-assets/fre+assets/tessel-tweet-2.png) + +
+
+ +
+
+ +**Bonus:** Try making Tessel tweet output from a module. + +
+ +
+ + +