且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-12-04 15:46:47

我们可以通过设置 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