4

I just started working with the google contacts api and can´t find an example how to work with the authentification stuff.

I used the Google Contacts API version 3.0 documentation for understanding the basic workflow with the contacts API, but I have no idea how to work with the authentification tokens.

After some searching in the web I found the tutorial Google OAuth2 C# but in this tutorial they are working with the UserCredential object. In the Google Contacts API version 3.0 documentation they used the RequestSettings object. This object has a constructor that accepts a ApplicationName and a GDataCredentials object.

So I tried the following code:

GDataCrendentials credentials = new GDataCredentials(CLIENTID);
credentials.Username = "<my gmail username>";
this._requestSettings = new RequestSettings(GetApplicationName, _credentials);

The ClientId I got from the second link I posted.

So I tried to access my contacts with the code:

Feed<Google.Contacts.Contact> f = _contactsRequest.GetContacts();
IList<IContact> mappedContacts = new List<IContact>();

foreach (var contact in f.Entries)
{
    //do some stuff with it
}

With this code I get an Google.GData.Client.GDataRequestException at the foreach:

{"Execution of request failed: https://www.google.com/m8/feeds/contacts/default/full"}

Could you please give me a suggestion what is wrong here?

WhiteIntel
  • 697
  • 1
  • 9
  • 24
  • https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth – heavyd Oct 07 '14 at 14:35
  • I also checked this, but the problem is that I need for the contact API an GDataCrendentials object and not a UserCredentials object. – WhiteIntel Oct 07 '14 at 14:47

1 Answers1

2

There is an OAuth2 sample included with the GData .NET client library:

https://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/oauth2_sample/oauth2demo.cs

The relevant source code is located here:

https://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/src/core/oauthutil.cs#200

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51