从Dotnet Google API获取用户电子邮件信息 [英] Get user email info from a Dotnet Google API

查看:97
本文介绍了从Dotnet Google API获取用户电子邮件信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为gData和Drive C#API工作Oauth2的两个单独的实现,分别将令牌信息存储在OAuth2Parameters和AuthorizationState中.我能够刷新令牌并将其用于必要的API调用.我正在寻找一种使用此方法来获取用户信息的方法,主要是电子邮件地址或域.

I'm have working two separate implementations of Oauth2 for both the gData and the Drive C# APIs, storing token information in an OAuth2Parameters and AuthorizationState respectively. I'm able to refresh the token and use them for the necessary API calls. I'm looking for a way to use this to get the user's information, mainly the email address or domain.

我尝试按照获取OAuth 2.0凭据的演示进行操作,但是我m收到类似于rapsalands的问题的编译错误

I tried following the demo for Retrieve OAuth 2.0 Credentials but I'm getting a compile error similar to rapsalands' issue here, saying it

can't convert from
'Google.Apis.Authentication.OAuth2.OAuth2Authenticator<
Google.Apis.Authenticatio‌​n.OAuth2.DotNetOpenAuth.NativeApplicationClient>'
to 'Google.Apis.Services.BaseClientService.Initializer'.

我刚刚获取了的最新版本Oauth2 api dlls ,所以我不这么认为.

I just grabbed the most recent version of the Oauth2 api dlls so I don't think that's it.

所有其他代码

All the other code samples I'm seeing around mention using the UserInfo API, but I can't find any kind of C#/dotnet api that I can use with it without simply doing straight GET/POST requests.

是否有一种方法可以使用我已经拥有的C#API的令牌获取此信息,而无需发出新的HTTP请求?

Is there a way to get this info using the tokens I already have with one of the C# apis without making a new HTTP request?

推荐答案

您需要使用 Oauth2Service 来检索有关用户的信息.

You need to use Oauth2Service to retrieve information about the user.

Oauth2Service userInfoService = new Oauth2Service(credentials);
Userinfo userInfo = userInfoService.Userinfo.Get().Fetch();

Oauth2Service 在以下库中可用:https://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google_OAuth2_API

这篇关于从Dotnet Google API获取用户电子邮件信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆