0

I need to get the list of activities of an user in Google+. My coding platform is node.js Express framework and I'm using google-api-nodejs-client package.

var googleapis = require('googleapis');
var auth = new googleapis.OAuth2Client();
var accessToken="XXXXXX......";
googleapis
    .discover('plus', 'v1')
    .execute(function (err, client) {
        if (err) {
            console.log('Problem during the client discovery.', err);
            return;
        }
        auth.setCredentials({
            access_token: accessToken
        });
        client
            .plus.people.get({ userId: 'me' })
            .withAuthClient(auth)
            .execute(function (err, response) {
                console.log('My profile details------>', response);
            });
        client
            .plus.activities.list({
                userId: 'me',
                collection: 'public',
                maxResults: 100
            })
            .withAuthClient(auth)
            .execute(function (err, response) {
                console.log('err----------------------------->',err);//EDIT
                console.log('activities---------------------->', response.items);
            });
    });

I got my profile details. But the activity is returning value: null. I checked my Google+ page to make sure that I have public posts. Also, I shared some posts to 'public' myself. Please help me find the bug in my code.

EDIT

Actually, there is an error. I found it by logging the value of err object in console as advised by Ryan Seys.

err--------------->

{
   "error": {
     "errors": [
      {
         "domain": "global",
         "reason": "insufficientPermissions",
         "message": "Insufficient Permission"
      }
     ],
   "code": 403,
   "message": "Insufficient Permission"
   }
}
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Foreever
  • 7,099
  • 8
  • 53
  • 55
  • Especially while debugging like this, you should also be taking a look at what is returned in "err". Check that and include it as part of the question. – Prisoner May 20 '14 at 16:32

2 Answers2

1

I think the problem is that you are specifying an empty fields parameter to client.plus.activities.list() instead of not providing a fields parameter at all. This tells it to return no fields for the results. Since the fields parameter is optional, you can omit it completely.

Try something like:

    client
        .plus.activities.list({
            userId: 'me',
            collection: 'public',
            maxResults: 100
        })
Prisoner
  • 49,922
  • 7
  • 53
  • 105
1

It would help if you provide the value of the err object but here's a few thoughts:

  1. Do you have Google+ API turned on for your project? See https://console.developers.google.com/ and the APIs and auth section of your project to enable the API.

  2. Are you requesting the right scopes for user profile data. See https://developers.google.com/apis-explorer/#p/plus/v1/plus.activities.list to try out the request. Click the OAuth button on that page to see the different types of scopes you may like to try requesting from the user. Some of the scopes I see right now are:

  3. Try adding an empty body field to the API request. This is a caveat of the current API client and some requests require you to enter a default empty {} after the parameter object.

    client
        .plus.activities.list({
            userId: 'me',
            collection: 'public',
            maxResults: 100
    
        }, {}) // <--- see the extra {} here! 
    
        .withAuthClient(auth)
        .execute(function (err, response) {
            console.log('activities---------------------->', response.items);
        });
    
Ryan Seys
  • 264
  • 1
  • 9