我正在为 gData 和 Drive C# API 开发两个独立的 Oauth2 实现,分别将令牌信息存储在 OAuth2Parameters 和 AuthorizationState 中。我可以刷新令牌并将其用于必要的 API 调用。我正在寻找一种方法来使用它来获取用户的信息,主要是电子邮件地址或域。
我尝试按照演示进行操作检索 OAuth 2.0 凭据 https://developers.google.com/drive/credentials?hl=en但我遇到了类似于 rapsalands 问题的编译错误here https://stackoverflow.com/questions/11994101/c-sharp-desktop-application-simple-example-how-to-upload-a-file-to-google-drive#comment22257204_11994650,说出来
can't convert from
'Google.Apis.Authentication.OAuth2.OAuth2Authenticator<
Google.Apis.Authentication.OAuth2.DotNetOpenAuth.NativeApplicationClient>'
to 'Google.Apis.Services.BaseClientService.Initializer'.
我刚刚下载了最新版本Oauth2 API DLL https://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google_OAuth2_API所以我认为不是这样的。
所有其他的code https://stackoverflow.com/questions/15471658/get-user-info-from-token-c-sharp samples https://stackoverflow.com/questions/7130648/get-user-info-via-google-api我看到周围提到使用 UserInfo API,但我找不到任何类型的 C#/dotnet api,我可以使用它而无需简单地执行直接 GET/POST 请求。
有没有办法使用我已经拥有的 C# api 之一的令牌来获取此信息,而无需发出新的 HTTP 请求?
你需要使用Oauth2Service
检索有关用户的信息。
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 https://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google_OAuth2_API
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)