Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get user email info from a Dotnet Google 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.

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'.

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.

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?

like image 824
squid808 Avatar asked Oct 20 '25 13:10

squid808


1 Answers

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

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

Oauth2Service is available on the following library: https://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google_OAuth2_API

like image 139
Burcu Dogan Avatar answered Oct 22 '25 03:10

Burcu Dogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!