Which are the correct Google+ scope variables to get email address and to post?

2.3k views Asked by At

I'm using spring-social-google (built from the git repo) to allow people to sign into my Spring MVC application (I already have facebook, twitter and linedin working). The form below allows me to authenticate, but an email address is not returned and posting to the Google+ timeline is prohibited:

<form action="<c:url value="/register/social/${providerId}" />" method="POST" id ="${providerId}Form" name = "${providerId}Form">
    <button type="submit"><img src="<c:url value='/resources/${providerId}/sign-in-with-${providerId}.png'/>" border="0"/></button>
    <input type="hidden" name="scope" value="https://www.googleapis.com/auth/plus.profile.emails.read" />                   
</form>

I think the issue is that I don't have the correct scope variables. I've tried some of the combinations here https://developers.google.com/+/api/oauth but I get told that the scope variables are all wrong. Which ones do I need?

This is the code for I'm using to get the email address:

public final class LoginConnectionSignUp implements ConnectionSignUp 
{   
    public String execute(Connection<?> connection) 
    {
        final UserProfile up = connection.fetchUserProfile();
        final String email = up.getEmail();
        // ...
    }

}
1

There are 1 answers

3
Prisoner On

There are a couple of issues here:

Posting to the Google+ Stream isn't supported by Google's API at this time. The package appears to let you create "app activity moments", which are stored on the user's profile... but these aren't posts to the stream. In order to generate an app activity, you need to include the https://www.googleapis.com/auth/plus.login scope.

Additionally, you can include either the email scope or the https://www.googleapis.com/auth/plus.profile.emails.read scope. With these scopes, you should be able to get the email address as part of the call to

Person person = google.plusOperations().getPerson("me");

So your input tag should probably look something like

<input type="hidden" name="scope" value="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read" />                   

(note the space between the two scopes to use).

Important note: The documentation talks about getting the email via a call such as

GoogleUserInfo userInfo = google.userOperations().getUserInfo();

while this may work for now, it is deprecated and scheduled to be removed in September. The userinfo scopes are also set to be deprectaed at this time. Don't use this method or these scopes. (And contact the author to tell them to deprecate it.)