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

时间:2021-04-19 15:31:17

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

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

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

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

1 个解决方案

#1


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.

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

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

标题字符串应包含: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

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

#1


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.

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

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

标题字符串应包含: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

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