Thursday, September 22, 2011

GooglePlus: ActivityFeed, PlusOnes, Replies, Reshares

Lets have a look how to get all the activity feeds of a user and how to get total number of plusone, replies and reshares.( Google has launched a limited API we can get only the count of plusone, replies and reshares).

I've used java api.

String userId=Constant.USERID;
Plus plus = new Plus(new NetHttpTransport(), new GsonFactory());
ActivityFeed feed = plus.activities().list(userId, "public").execute();

 while (feed.getItems() != null) {
           for (Activity activity : feed.getItems()) {
                     ActivityObject obj = activity.getPlusObject();
                      ActivityObjectPlusoners plusoners = obj.getPlusoners();
                     System.out.print("Plus One : "+plusoners.getTotalItems());
                      ActivityObjectReplies replies = obj.getReplies();
                      System.out.print("Replies : "+replies.getTotalItems());
                     ActivityObjectResharers reshares = obj.getResharers();
                    System.out.println("Reshares : "+reshares.getTotalItems());
Plus.Activities.List list = plus.activities().list(userId, "public");                list.setPageToken(feed.getNextPageToken()); feed = list.execute();

Similarly ActivityObjectAttachment objects can be accessed.
Its pretty easy but very limited as well. :(

No comments:

Post a Comment