从Dotnet Google API获取用户电子邮件信息

squ*_*808 3 .net c# gdata google-drive-api

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

我尝试了演示了以下检索OAuth 2.0凭证,但我发现类似rapsalands'的问题编译错误在这里,说它

can't convert from
'Google.Apis.Authentication.OAuth2.OAuth2Authenticator<
Google.Apis.Authenticatio??n.OAuth2.DotNetOpenAuth.NativeApplicationClient>'
to 'Google.Apis.Services.BaseClientService.Initializer'.
Run Code Online (Sandbox Code Playgroud)

我刚刚抓住了最新版本的Oauth2 api dll,所以我不认为就是这样.

我正在使用UserInfo API提到的所有其他代码 示例,但我找不到任何类型的C#/ dotnet api,我可以使用它而不需要直接执行GET/POST请求.

有没有办法使用我已经拥有的一个C#apis的令牌获取此信息而不会发出新的HTTP请求?

Bur*_*gan 6

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

Oauth2Service userInfoService = new Oauth2Service(credentials);
Userinfo userInfo = userInfoService.Userinfo.Get().Fetch();
Run Code Online (Sandbox Code Playgroud)

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