Database Reference
In-Depth Information
￿
User's real name (Data Analytics)
￿
User's Twitter handle(@twtanalyticsbk)
￿
User's location (Tempe, AZ)
￿
URL, which typically points to a more detailed profile of the user on an external
website ( tweettracker.fulton.asu.edu/tda )
￿
Textual description of the user and his interests (Twitter Data Analytics is a topic
for...)
￿
User's network activity information on Twitter (1 follower and following 6
friends)
￿
Number of Tweets published by the user (1 Tweet)
￿
Verified mark if the identity of the user has been externally verified by Twitter
￿
Profile creation date
Listing 2.2
Using Twitter API to fetch a user's profile
public JSONObject GetProfile(String username) {
...
// Step 1: Create the API request using the supplied
username
URL url = new URL( "https://api.twitter.com/1.1/users/
show.json?screen_name=" +username);
HttpURLConnection huc = (HttpURLConnection) url.
openConnection();
huc.setReadTimeout(5000);
// Step 2: Sign the request using the OAuth Secret
consumer.sign(huc);
huc.connect();
...
/ ** Step 3: If the requests have been exhausted,
* then wait until the quota is renewed
* /
if(huc.getResponseCode()==429) {
try {
huc.disconnect();
Thread.sleep( this .GetWaitTime( "/users/
show/:id" ));
flag = false;
...
// Step 4: Retrieve the user's profile from Twitter
bRead = new BufferedReader(new InputStreamReader((
InputStream) huc.getContent()));
...
profile = new JSONObject(content.toString());
...
return userobj;
}
Source: Chapter2/restapi/RESTApiExample.java
 
Search WWH ::




Custom Search