-1

I already have the user authenticated using the browser. Now I want to send this token to the server and the server has to get the user details like first name, last name and email address.

I've done this with Facebook recently and it was simple because there was an easy to use library for it.

I can't seem to figure out how to use the Google library. I am using this library https://code.google.com/p/google-api-dotnet-client/ which interacts with the google API.

Any tips or examples on the internets which could show me how to do this? I just know it's something really simple and that I might be going about this entirely the wrong way..

I need the Stack wisdom!!! Feed me!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Welcome to Stack Overflow! This looks like the beginning of a good question, but you might get better results if you include your code for what you've tried so far. People can then see what you are doing wrong and post a correction rather than having to give you a complete example. Also, asking for off-site resources is off-topic as it tends to attract spam. – GenericJon Jun 06 '14 at 10:49
  • Take a look in this thread - http://stackoverflow.com/questions/23759400/net-client-for-the-google-people-api, I think you will find it useful. – peleyal Jun 06 '14 at 12:44

2 Answers2

0
var tokeninfoUri = "https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=" + accessToken;

var hc = new HttpClient();

var webResponse = hc.GetAsync(tokeninfoUri).Result;

This returns JSON similar to this

public string Expires_In { get; set; }
public string Audience { get; set; }

Then I call this API to get the user info

const string userInfoUrl = "https://www.googleapis.com/oauth2/v1/userinfo";
var hc = new HttpClient();
hc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
var webResponse = hc.GetAsync(userInfoUrl).Result;

So I didn't need any library to help me. But it would be nice if there was a library which done all this for me. It took me a few hours to figure this out.

0

The Google APIs client library for .NET should do the job for you. All the APIs are available here: https://developers.google.com/api-client-library/dotnet/apis/

You will need to use the following API: https://developers.google.com/api-client-library/dotnet/apis/oauth2/v2, which is available in NuGet repository: http://www.nuget.org/packages/Google.Apis.Oauth2.v2/

peleyal
  • 3,472
  • 1
  • 14
  • 25