且构网

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

Gmail OAuth用于获取用户详细信息

更新时间:2023-12-04 10:09:16

如果你浏览了你提供的链接,解决方案就在那里。

如下所示...

If you go through the link you have provided, the solution is there itself.
It says like below...


完成此步骤后,用户将被重定向回您的网站(http://www.yourdomain.com/oauth2callback)。以下是此回调代码。其目的是获取刷新令牌和访问令牌:


After this step user is redirected back to your website (http://www.yourdomain.com/oauth2callback). Following is this callback code. Its purpose is to get a refresh-token and an access-token:
WebServerClient consumer= new WebServerClient(server, clientID, clientSecret);
consumer.ClientCredentialApplicator =
    ClientCredentialApplicator.PostParameter(clientSecret);
IAuthorizationState grantedAccess = consumer.ProcessUserAuthorization(null);

string accessToken = grantedAccess.AccessToken;



访问令牌通常有效最多一个小时,并允许您访问用户的数据。您还收到了刷新令牌。刷新令牌可用于在先前过期后请求新的访问令牌。


An access token is usually valid for a maximum of one hour, and allows you to access the user’s data. You also received a refresh token. A refresh token can be used to request a new access token once the previous expired.

示例项目链接 -

参考dotnetopenid / samples / OAuthConsumer / GoogleAddressBook.aspx.cs [ ^ ]和dotnetopenid / samples / OAuthConsumer [ ^ ]完整项目。

谢谢......

Sample Project links -
Refer dotnetopenid / samples / OAuthConsumer / GoogleAddressBook.aspx.cs[^] for sample page and dotnetopenid / samples / OAuthConsumer[^] for full project.
Thanks...