I use the Google APIs for .Net, but no doubt you can find the same way to get this information using a different version of the API. As indicated by user872858 , the userinfo.profile area is deprecated ( google article ).
To get information about the user profile, I use the following code (the rewritten part from the Google example ):
IAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow( new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = Secrets, Scopes = new[] { PlusService.Scope.PlusLogin,"https://www.googleapis.com/auth/plus.profile.emails.read" } }); TokenResponse _token = flow.ExchangeCodeForTokenAsync("", code, "postmessage", CancellationToken.None).Result; // Create an authorization state from the returned token. context.Session["authState"] = _token; // Get tokeninfo for the access token if you want to verify. Oauth2Service service = new Oauth2Service( new Google.Apis.Services.BaseClientService.Initializer()); Oauth2Service.TokeninfoRequest request = service.Tokeninfo(); request.AccessToken = _token.AccessToken; Tokeninfo info = request.Execute(); if (info.VerifiedEmail.HasValue && info.VerifiedEmail.Value) { flow = new GoogleAuthorizationCodeFlow( new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = Secrets, Scopes = new[] { PlusService.Scope.PlusLogin } }); UserCredential credential = new UserCredential(flow, "me", _token); _token = credential.Token; _ps = new PlusService( new Google.Apis.Services.BaseClientService.Initializer() { ApplicationName = "Your app name", HttpClientInitializer = credential }); Person userProfile = _ps.People.Get("me").Execute(); }
Moreover, you can access almost anyone using userProfile.
UPDATE. To get this code, you must use the appropriate scope in the Google login button. For example, my button:
<button class="g-signin" data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read" data-clientid="646361778467-nb2uipj05c4adlk0vo66k96bv8inqles.apps.googleusercontent.com" data-accesstype="offline" data-redirecturi="postmessage" data-theme="dark" data-callback="onSignInCallback" data-cookiepolicy="single_host_origin" data-width="iconOnly"> </button>
LaoR Jul 01 '14 at 12:30 2014-07-01 12:30
source share