Common issues and solutions for the new Google+ platform release

So yesterday, we had our big launch and developers have be jumping in and writing code (you guys are awesome!).  A number of folks have been encountering the same issues and I think it’s probably a good time to summarize a few common issues and resolutions:

Common issues and fixes

Here are the biggest issues I have seen so far, just little quirks are super easy to fix. These have been coming up because a few things have changed so there are a few tricks you need to learn.

#1 Moments: insert is returning 401

If you have been using history, the API has changed slightly, you now need to request the specific types of app activities that you are requesting.  The following code should help you get started:

Rendering the sign-in button with appropriate scopes:

<span id="signinButton">
  <span
    class="g-signin"
    data-callback="signinCallback"
    data-clientid="CLIENT_ID"
    data-cookiepolicy="single_host_origin"
    data-requestvisibleactions="http://schemas.google.com/AddActivity"
    data-scope="https://www.googleapis.com/auth/plus.login">
  </span>
</span>

The important line is data-requestvisibleactions.  In this line, you need to add all of the activity types that you will be writing to a user’s app activities.

Now you should be able to write moments.  The following example shows this from JavaScript:

var payload={
    'type': 'https://schemas.google.com/AddActivity',
    'target': {'url':'https://developers.google.com/+/plugins/snippet/examples/thing'}
};

var args = {
      'path': '/plus/v1/people/me/moments/vault',
      'method': 'POST',
      'body': JSON.stringify(payload),
      'callback': function(response) {
        console.log(response);
      }
    };

gapi.client.request(args);

Or, another example passing a moment payload that does not include a URL:

      var payload = {
        "target": {
          "id" : "replacewithuniqueidforaddtarget",
          "image" : "http:\/\/www.google.com\/s2\/static\/images\/GoogleyEyes.png",
          "type" : "http:\/\/schema.org\/CreativeWork",
          "description" : "The description for the activity",
          "name":"An example of AddActivity"
        },
        "type":"http:\/\/schemas.google.com\/AddActivity",
        "startDate": "2012-10-31T23:59:59.999Z"
      };
      var args = {
        'path': '/plus/v1/people/me/moments/vault',
        'method': 'POST',
        'body': JSON.stringify(payload),
        'callback': function(response) {
           console.log(response);
         }
      };

      gapi.client.request(args);

 

#2 The [inesrt your favorite language] sample/library doesn’t work with my old code!!!

We have had a few minor revisions to the client libraries recently.  To get some code that will get you going right away, clone one of our GitHub repos and then use that for updating your software and read the quick-start documentation. Also of note, the latest and greatest client libraries are available from the Google+ downloads page.

#3 The client library is behaving strangely

If this is happening, there are a few things that could be causing issues:

You are requesting the wrong scopes.  The plus.me scope should never be included with the plus.login scope.  Also, I’m going to discourage you from using the userinfo.email scope unless you really need someone’s email address. Also, with the plus.login scope you can potentially get an email… it will not be verified, however.  The userinfo.email scope will deliver the email that is associated (and verified) for the authorized user.

You are using an older version of the client library. We constantly are updating the client libraries to address issues that we encounter and that are reported from the community. If you are seeing strange behavior from your client library, try getting the latest one from the Google+ client library downloads page.

Some more information on error codes:

500

This is an error that you can’t do very much about.  If you’re encountering this issue, please file an issue in the issue tracker.

404

This is a conventional “not found” error.  In API calls, this can mean that a resource was not found, for example searching for a user and you have the wrong id, this could return a 404.

401

This is a separate type of error from the 400 and is more specific to your operations.  For example, if you are using Google+ app activties, and you haven’t properly configured your client to enable writing app activities to Google+ but you still have a valid client, you could see a 401 error.

400

Grant error indicates that you either have exchanged an authorization code that has already been used, or you are trying to use an expired access token.  Reset your credentials!

Responses

unauthorized_client

This means that you’re trying to make an API call with a client ID that is different from the one issued to the client that generated a token (usually an access token).

See also