如何在使用Google帐户OAuth API时获取Google用户ID(电子邮件)

6 oauth google-openid

我是OAuth的新手,想要使用OAuth从Google获取用户ID(电子邮件地址).

但我不想获取用户的Google通讯录信息.

Sac*_*mar 7

我们可以通过制作请求令牌的范围来获取谷歌电子邮件地址而不是联系人.

"https://www.google.com/accounts/OAuthGetRequestToken?scope=https://www.googleapis.com/auth/userinfo#email";
Run Code Online (Sandbox Code Playgroud)

现在进行授权调用以获得如下响应:

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

这里通过说授权调用意味着在标头中使用所需的参数进行HTTP Get请求.

标题字符串应包含:realm,consumerKey,signatureMethod,signature,timestamp,nounce,OAuthVersion,token

请参阅http://googlecodesamples.com/oauth_playground以验证您的代码并查看正确的标题字符串参数