Java Reference
In-Depth Information
Content-Type: application/x-www-form-urlencoded
Authorization:
OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",
oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
oauth_signature="tnnArxj06cWHq44gCs1OSKk%2FjLY%3D",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1318622958",
oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
oauth_version="1.0"
Content-Length: 76
Host: api.twitter.com
status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21
This request is similar, except that it now contains a special “Authorization” OAuth header. This
header contains the following information:
oauth_consumer_key : Identifies the application making the REST request.
oauth_nonce : A unique token generated for each request. This is to prevent the same request
being sent multiple times.
oauth_signature : A hash of the request and some secret values that can be used to check
the request on the server's side to make sure it has not been tampered with.
oauth_signature_method : The method that was used to construct the signature.
oauth_timestamp : Indicates when the request was created. OAuth services will reject
requests that were created too far in the past.
oauth_token : The access token representing the permission by the user to share access to
your application.
oauth_version : The version of the OAuth protocol being used.
It is possible to construct this header manually and send it along every request, e.g., using
HttpUrlConnection . Since this is a complex process involving a great deal of steps, you can use
Google's Java OAuth Client Library instead.
The first thing you'll need to do is create a Twitter API key to identify your application. This is the
oath_consumer_key mentioned previously. To create it, navigate to https://apps.twitter.com/ ,
log in with your Twitter account (it's easy to create one if you haven't already), and select Create
New App. You will need to fill in some details:
Name: The name given to your application. For this example, the name
NAMEJavaTestClient is used. Fill in your name instead of “NAME” (application names
need to be unique).
Description: “Testing Twitter's REST Service in Java.”
Website: You can just put a placeholder here, e.g., http://www.example.com .
Callback URL: Fill in nothing.
Accept the agreements and press Create Your Twitter Application. If all goes well, you'll be brought
to a page with details for your app. See Figure 10-20.
Search WWH ::




Custom Search