Jerry
Jerry

Reputation: 21

retrieve all my Activities from Google+ programmatically

I was trying to write a program to retrieve all my activities from Google+. I studied the sample code provided by Google and wrote my program like this:

// Fetch the available activities
Plus.Activities.List listActivities = plus.activities().list("me", "public");

listActivities.setMaxResults(20L);

ActivityFeed feed;
try {
  feed = listActivities.execute();
} catch (HttpResponseException e) {
  log.severe(Util.extractError(e));
  throw e;
}
// Keep track of the page number in case we're listing activities
// for a user with thousands of activities. We'll limit ourselves
// to 5 pages
int currentPageNumber = 0;
String token = "";
while (token != null && feed != null && feed.getItems() != null && currentPageNumber < 5) {
  currentPageNumber++;

  System.out.println();
  System.out.println("~~~~~~~~~~~~~~~~~~ page "+currentPageNumber+" of activities ~~~~~~~~~~~~~~~~~~");
  System.out.println();

  for (Activity activity : feed.getItems()) {

    show(activity);
    System.out.println();
    System.out.println("------------------------------------------------------");
    System.out.println();
  }

  // Fetch the next page
  token = feed.getNextPageToken();
  System.out.println("next token: " + token);
  listActivities.setPageToken(token);
  feed = listActivities.execute();
} 

The problem is that this only allows me to retrieve my "public" activities. I also have some private activities and this program didn't get them. The problem is related to

plus.activities().list("me", "public");

This list function requires an input parameter, the collection of activities to list. Here, it is "public". I want to retrieve all activities instead of just public ones. But based on

https://developers.google.com/+/api/latest/activities/list

The only available input for this collection of activities to list is "public". So my questions are:

  1. Is it possible to retrieve all my Activities (both public and non-public) from Google+ programmatically?
  2. If it is possible, how can I do it with Java?

Thanks a lot!

Upvotes: 2

Views: 1237

Answers (2)

Diwa Iyer
Diwa Iyer

Reputation: 233

By authorizing, you get just these two scopes.

-Know who you are on Google https://www.googleapis.com/auth/plus.me

-View your email address https://www.googleapis.com/auth/userinfo.email

As you can see, it doesn't open up access to non-public activity.

The API page says,

Acceptable values for 'collection' are: "public" - All public activities created by the specified user.

Reference: Google+ API page. Not able to link to it here.

Upvotes: 1

Chirag Shah
Chirag Shah

Reputation: 3674

The official Google+ API only provides read-only access to public data. So, you'll only be able to use "public" as the collection of activities.

Upvotes: 2

Related Questions