使用 Google 帐户 OAuth API 时如何获取 Google 用户 ID(电子邮件) [英] How to get the Google user ID (email) when using Google Account OAuth API
问题描述
我是 OAuth 的新手,想使用 OAuth 从 Google 获取用户 ID(电子邮件地址).
I am new to OAuth, and want to get the user ID (an email address) from Google using OAuth.
但我不想获取用户的 Google 通讯录信息.
But I don't want to get the user's Google Contacts Information.
推荐答案
我们可以通过设置 request token 的 scope 来获取 google Email 地址,而不是联系人:
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);
这里所说的授权调用是指在标头中使用必需的参数发出 HTTP Get 请求.
Here by saying authorized call mean to make the HTTP Get request with required paramaters in header.
header 字符串应该包含:realm、consumerKey、signatureMethod、signature、timestamp、nounce、OAuthVersion、token
header string should contain: realm, consumerKey, signatureMethod, signature, timestamp, nounce, OAuthVersion, token
请参阅 http://googlecodesamples.com/oauth_playground 以验证您的代码并查看正确的标头字符串参数
Please refer to http://googlecodesamples.com/oauth_playground to verify your code and to see the correct header string parameters
这篇关于使用 Google 帐户 OAuth API 时如何获取 Google 用户 ID(电子邮件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!