Scenario:
- The user wishes to send an update to Twitter
- A thing will be created called "Twitter" that is configured to integrate with Twitter
- 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
- This method is called by UI or API by entering a string (request object) as the argument for posting
Prerequisites:
- Access to Twitter accounts must first be enabled by performing OAuth authentication
- When connecting to Twitter, it's important to have write permission to enable updates to be sent to Twitter
Steps:
1. Create "Twitter" thing
- Click "Things" in main menu to open the "Things" tab
- Click "+" button to show "Create Thing" dialog
- Set name to "Twitter"
- Save thing by clicking "Save"
2. Configure OAuth1
Prerequisites
- Register your Twitter application at: https://dev.twitter.com/apps (follow this video tutorial)
-
On the application registration form:
- Set "Application Website" to http://console.gadgetkeeper.com/
- Set "Application Type" to "web"
- Set "Callback URL" to http://console.gadgetkeeper.com/connect
- In the "Information" section of the "Thing: Twitter" tab, click "Edit" to show "Edit Thing" dialog
- Select the "Authentication" tab in the dialog, and then select "OAUTH1" in the drop-down menu for "Authentication"
- Enter your Twitter Client Id
- Enter your Twitter Client Secret
- Set "Request token url" to "https://api.twitter.com/oauth/request_token"
- Set "Authorization url" to "https://api.twitter.com/oauth/authorize"
- Set "Access token url" to "https://api.twitter.com/oauth/access_token"
- Set "Params" to "oauth_access_type=write" (enables updates to be sent to Twitter)
- 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
- In the "Information" section of the "Thing: Twitter" tab, click "Connect"
- When the Twitter page opens, click "Authorize app":
4. Create "updateStatus" method
- Open the "Methods" section of the "Thing: Twitter" tab
- Click "New" to open "Create Method" dialog
- Set name to "updateStatus"
- Select "script" as the type of method
- Select "string" as the "Request Data Type"
- 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
- Open the "Methods" section of the "Thing: Twitter" tab
- Select the "updateStatus" method
- Click to open "Edit Script" dialog
-
Insert the following JavaScript code for the "updateStatus" method:
- 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
- Click to open "Call method" dialog
- Type in a string as an example argument for the "updateStatus" method (sent as a JSON encoded string for posting on Twitter)
- Click "Call" to execute the method
Log onto Twitter and check for the new posting