Child pages
  • Twitter integration
Skip to end of metadata
Go to start of metadata

Content and purpose

Attached to the page are 2 Apstrata server-side scripts that will allow you to easily integrate your application to twitter.

Note that tweeting is a twofold process:

1) first, you need to authorize a twitter application on your twitter account, unless the user has already authorized the application (you only have to do this once, of course)
2) second, your web/mobile application invokes Apstrata to tweet

  File Modified
JavaScript File social.twitter.integrate.js Jan 17, 2013 by karim saikali
JavaScript File social.twitter.api.js Jan 17, 2013 by karim saikali

Authorize the twitter application

Step 1- Ask for an authorization URL


use the "social.twitter.integrate" script

Parameters
  • command : the call to make on twitter. Use. "getRequestToken"
  • requester : some value that identifies the initiator of the tweet request (for example, a phone number. Don't user email addresses, or remove the '@')
  • consumerKey: the consumer key of the twitter application you need to integrate with. If not specified, will use the default (see in code)
  • consumerSecret: the consumer secret of the twitter application. Optional as well, if not specified, will use the default
  • store: (optional) the store where the optional configuration document (see "Note" below) is created and were the

requestToken and requestSecret will be temporarily stored.

Returned values

  • When successful
"result": {

	"status": "success",

    "authorizationAndSecret": {

    	"authorizationUrl": "[The_Url_sent_by_twitter_that_you_need_to_call_to_authorize_the_application]",

    	"requestToken": "[the_request_token_to_use_to_get_an_access_token]",

    	"requestSecret": "[the_request_secret_to_use_to_get_an_acces_token]"
  	}

}

 

  • When failure
"result": {

	"status": "failure",

    "errorDetails": [error]

}

 

Step 2 - Authorize the Twitter application and get an access token and access secret

Next step is to call twitter using the returned authorization URL. This will display a page where you will have to explicitly authorize the application on your account. Once you authorize the application, tweeter calls back the server side script that will create the access token and access token secret.

 

Notes
  1. You can choose to specify the values of consumerKey, consumerSecret and callbackUrl in a configuration document. In that case, switch the value of the "useDocument" variable to "true" in the code and create a configuration document of which key = "Twitter" + appKey.  1
  2. Once you authorize the application on tweeter, this latter calls back the script that will creates/updates a document in the Apstrata store, key of which = "twitter_requester_identifier". This document contains a token and token secret field for every authorized twitter application for the given requester identifier (respectively "token_consumerkey" and "secret_consumerkey"). You can use this document after authorizing the application the first time, in order to avoid another unnecessary authorization.

 

Tweet on the user's twitter account

Use the social.twitter.api script.

Parameters

  • consumerKey: the twitter application key
  • consumerSecret: the twitter application secret
  • accessToken: the token returned by twitter after authorizing the application (step 1 - described in paragraph 3.2.1)
  • accessTokenSecret: the secret returned by twitter after authorizing the application (step 1 - described in paragraph 3.2.1)
  • command: the api function to call ("tweet")  
  • tweetString: the message to tweet

 

  • No labels