Social Network API Test


  • What can obtain from Graph API in Facebook? (Assume user is not using my app)
    1. Search by name: https://graph.facebook.com/v2.2/search?q=Guangyuan+Piao&type=user&access_token="your access token"
    2. Get name, id
    3. Search user information by id: https://graph.facebook.com/v2.2/id
    4. Get id, first_name, last_name, link, name, updated_time

  • Limit on Google Plus API?
    1. per day (10,000) and per second (5)

  • Limit on Twitter API?
    1. user look up 180/time_window (15min in v.1.1)
    2. get user timeline 180/time_window (15min in v.1.1)
    3. How to get user timeline with paging?
- The example below get 100 statuses / page for 10 times (for loop) to get maximum 1000 tweets from user timeline.
- However, because every call for getUserTimeline() will use one rate, it is better to check the status list and break the look if there's no more status in the current page....

1:  for (int j=1; j<11; j++) {  
2:        Paging page = new Paging (j, 100); // page number, number per page  
3:        List<Status> statuses = twitter.getUserTimeline(user.getId(), page); // rate will for -1 each call  
4:       if (statuses.size() < 1) {  
5:              break;  
6:       }   
7:  }  



  • Twitter Helper 


1:    TwitterFactory factory;  
2:    Twitter twitter;  
3:       public TwitterHelper() {  
4:            // Configuration of Twitter API  
5:            ConfigurationBuilder cb = new ConfigurationBuilder();  
6:       cb.setDebugEnabled(false)  
7:        .setOAuthConsumerKey(consumerKey)  
8:        .setOAuthConsumerSecret(consumerSecret)  
9:        .setOAuthAccessToken(accessToken)  
10:        .setOAuthAccessTokenSecret(accessSecret);  
11:      // Initialize Twitter Instance  
12:      factory = new TwitterFactory(cb.build());  
13:      twitter = factory.getInstance();  
14:       }  
15:       public int getStatusesRemainingRate() {  // check /statuses/user_timeline endpoint remaining rate

16:            int i = 0;  
17:            RateLimitStatus status;  
18:            try {  
19:                 status = twitter.getRateLimitStatus().get("/statuses/user_timeline");  
20:                 i = status.getRemaining();  
21:            } catch (TwitterException e) {  
22:                 System.out.println(e.getMessage());  
23:            }  
24:            return i;  
25:       }  

No comments:

Post a Comment