Skip to end of metadata
Go to start of metadata

Scenario

  1. The user wishes to send an update to Twitter
  2. A thing will be created called "Twitter" that is configured to integrate with Twitter
  3. An "updateStatus" method will be created as a function that uses the POST method of the http object to call api.twitter.com with a request object for posting
  4. This method is called by UI or API by entering a string (request object) as the argument for posting

Prerequisites:

  1. Access to Twitter accounts must first be enabled by performing OAuth authentication
  2. When connecting to Twitter, it's important to have write permission to enable updates to be sent to Twitter

Steps

1. Create "Twitter" thing


  1. Click "Things" in main menu to open the "Things" tab
  2. Click "+" button to show "Create Thing" dialog
  3. Set name to "Twitter"
  4. Save thing by clicking "Save"

2. Configure OAuth1


Prerequisites

  1. In the "Information" section of the "Thing: Twitter" tab, click "Edit" to show "Edit Thing" dialog
  2. Select the "Authentication" tab in the dialog, and then select "OAUTH1" in the drop-down menu for "Authentication"
  3. Enter your Twitter Client Id
  4. Enter your Twitter Client Secret
  5. Set "Request token url" to "https://api.twitter.com/oauth/request_token"
  6. Set "Authorization url" to "https://api.twitter.com/oauth/authorize"
  7. Set "Access token url" to "https://api.twitter.com/oauth/access_token"
  8. Set "Params" to "oauth_access_type=write" (enables updates to be sent to Twitter)
  9. Save the new settings for the "Twitter" thing by clicking "Save"
"Client Id" and "Client Secret" can be found on: https://dev.twitter.com/apps  by clicking the name of the app, and then clicking "Test OAuth" when the app page opens up

"Client Id" is the 25-character string labeled as "Consumer key", and  "Client Secret" is the 50-character string labeled as "Consumer secret"

3. Connect "Twitter" thing to your Twitter account


  1. In the "Information" section of the "Thing: Twitter" tab, click "Connect"
  2. When the Twitter page opens, click "Authorize app":

4. Create "updateStatus" method


  1. Open the "Methods" section of the "Thing: Twitter" tab
  2. Click "New" to open "Create Method" dialog
  3. Set name to "updateStatus"
  4. Select "script" as the type of method
  5. Select "string" as the "Request Data Type"
  6. Click to save new method

The string used for "Request Data Type" will be entered in as a string argument when calling this method, and will be sent as a request object for posting on Twitter

5. Implement "updateStatus" method logic


  1. Open the "Methods" section of the "Thing: Twitter" tab
  2. Select the "updateStatus" method
  3. Click to open "Edit Script" dialog
  4. Insert the following JavaScript code for the "updateStatus" method:

  5. Save script by clicking "Save"

Whenever this method is called, the given argument will be inserted in the request object as "statusText"

This function uses the POST method of the http object to call the URL with the request object

6. Call "updateStatus" method


  1. Click to open "Call method" dialog
  2. Type in a string as an example argument for the "updateStatus" method (sent as a JSON encoded string for posting on Twitter)
  3. Click "Call" to execute the method

Log onto Twitter and check for the new posting

 

 

 

  • No labels