简体   繁体   English

使用Google OAuth2获取用户信息,例如名称,电子邮件

[英]Fetching User Info like Name, Email using Google OAuth2

I am using Google's .NET SDK in my application and would like to get the user info. 我在应用程序中使用Google的.NET SDK,并希望获取用户信息。 I have obtained the UserCredential object using the below scopes. 我已经使用以下范围获得了UserCredential对象。

  new[] { Uri.EscapeUriString("https://www.googleapis.com/auth/userinfo.email"), 
          Uri.EscapeUriString("https://www.googleapis.com/auth/userinfo.profile") }

After this am looking for a UserInfoService to fetch the name and email of the user but it is not to be found. 之后,寻找UserInfoService来获取用户的名称和电子邮件,但找不到它。 Note I am only using Google's SDK and not handling the request and response myself. 请注意,我仅使用Google的SDK,而不自己处理请求和响应。
I have found few samples in other sites but those don't use the Google API and are forming the 我在其他网站上发现的样本很少,但是这些样本未使用Google API,并且正在形成
request url and need to parse the response JSON. 请求网址,并且需要解析响应JSON。

Is there a way I can get the UserInfo without myself creating the request url and leave this to be handled by the Google API ? 有没有一种方法可以让我得到UserInfo没有自己创建请求的URL,离开这个由谷歌API来处理?

That was already asked before here: .NET client for the Google People API 在此之前已经有人问过: Google People API的.NET客户端

Anyway, you should use the OAuth 2.0 library, and it looks like you will be interested in the UserInfoResource.GetRequest . 无论如何,您应该使用OAuth 2.0库,并且您似乎会对UserInfoResource.GetRequest感兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM