How to get the Google user ID (email) when using Google Account OAuth API
Asked Answered
C

2

6

I am new to OAuth, and want to get the user ID (an email address) from Google using OAuth.

But I don't want to get the user's Google Contacts Information.

Cerberus answered 22/7, 2011 at 8:33 Comment(0)
A
7

We can get google Email address only not the contacts by making the scope of request token Like :

"https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/userinfo#email";

Now do a authorized call to get the response like :

var responseText = oAuthConsumer.GetUserInfo("https://www.googleapis.com/userinfo/email", consumerKey, consumerSecret, token, tokenSecret);

Here by saying authorized call mean to make the HTTP Get request with required paramaters in header.

header string should contain: realm, consumerKey, signatureMethod, signature, timestamp, nounce, OAuthVersion, token

Please refer to http://googlecodesamples.com/oauth_playground to verify your code and to see the correct header string parameters

Artieartifact answered 20/10, 2011 at 13:7 Comment(0)
B
0

Go to the Google Cloud Console. Create a new project or select an existing project from the project dropdown menu. Click on the menu icon (☰) in the top left corner and navigate to "APIs & Services" > "Credentials". On the Credentials page, click the "Create credentials" button and select "OAuth client ID" from the dropdown menu. Choose the application type that matches your use case. For example: "Web application" if you're building a web application. "Desktop app" if you're building a desktop application. "Mobile app" if you're building a mobile application. Configure the authorized JavaScript origins and redirect URIs according to your application's needs. These are the URLs that Google will allow for OAuth authentication. Click the "Create" button to create the OAuth client ID. Once created, you will be provided with the client ID and client secret. Make sure to keep these credentials secure and don't share them publicly.

Buxom answered 23/5, 2023 at 18:25 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Felsite

© 2022 - 2024 — McMap. All rights reserved.