Search code examples
gmailcontactsimpersonationaccounts

Does google Contact api support 2-legged OAuth 2.0?


I want to impersonate Gmail accounts Contacts but could not find the way how to use 2-legged OAuth 2.0 to do that. I am using C# Google client liberary.


Solution

  • Google didn't provide any new Contact API for OAuth 2.0. You can use Google.GData.Contacts.dll to perform Contact OAuth 2.0 impersonation. Use GOAuth2RequestFactory object to assign Access Token to contact service.

                    OAuth2Parameters parameters = new OAuth2Parameters
               {
                   AccessToken = _AccessToken
               };
    
                GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "GamailContactsReader", parameters);
    
                // Connecting the Contats service.
                ContactsService service = new Google.GData.Contacts.ContactsService("GamailContactsReader");
                service.RequestFactory = requestFactory;               
    
                GroupsQuery groupQuery = new GroupsQuery(GroupsQuery.CreateGroupsUri(_EmailAddress));
                groupQuery.NumberToRetrieve = int.MaxValue;
    
                GroupsFeed groupFeed = service.Query(groupQuery);