Hi

Several months ago I'd written a prototype for an application that would 
automatically add contacts to Google Apps users (in vb.net using the client 
library). 


Imports Google.GData.Apps
Imports Google.GData.Client
Imports Google.GData.Contacts


' Authenticate a Contacts Service object
sAuthToken = AppsService.GetNewAuthenticationToken(<MyGoogleDomain>, 
<AdminEmail>, <AdminPassword>)

Dim gAppContacts As Google.GData.Contacts.ContactsService
gAppContacts = New Google.GData.Contacts.ContactsService(sApplicationName)

gAppContacts.SetAuthenticationToken(sAuthToken)

' set up feed to the email account
Dim query As ContactsQuery = New 
ContactsQuery(ContactsQuery.CreateContactsUri(<EmailAddressOfUser>)) ' 
EXCEPTION THROWN HERE

Dim feed As ContactsFeed = service.Query(query)

' create contacts and add to email account via the feed
Dim inserted As List(Of ContactEntry) = New List(Of ContactEntry)

If Not feed Is Nothing Then

    Dim newContact As ContactEntry = New ContactEntry

      newContact.Title.Text = "TestContact"

      Dim primaryEmail As EMail = New EMail(<TestContactAddress>)

      primaryEmail.Primary = True
      primaryEmail.Rel = ContactsRelationships.IsWork
      newContact.Emails.Add(primaryEmail)

      newContact.Content.Equals("Course Tutor")

      ' insert entry into the feed and add to list of contacts
      feed.Insert(newContact )

End If

I came back to this recently to find it no longer works - the 401 - 
unauthorised error gets thrown at the point shown. I am using the 
SetAuthenticationToken method for the Google Groups service - no problems 
with that.

I've spent some quite some time trying alternatives, the latest of which is 
this;

Dim gAppContactsService As GContactsService.ContactsService

gAppContactsService = New 
GContactsService.ContactsService(<MyApplicationName>)

Dim authFactory As Google.GData.Client.GAuthSubRequestFactory = Nothing
authFactory = New Google.GData.Client.GAuthSubRequestFactory("cp", 
BO.Constants.APPLICATION_NAME)

gAppContactsService.RequestFactory = authFactory

gAppContactsService.setUserCredentials(<AdminEmail>, <AdminPassword>)
 
Dim query As GConts.ContactsQuery = New 
GConts.ContactsQuery(GConts.ContactsQuery.CreateContactsUri( _
  <UserEmailAddress>)) ' "401 unathorised" EXCEPTION THROWN

Dim feed As GConts.ContactsFeed = gAppContactsService.Query(query)

...


Exception thrown is

Google.GData.Client.GDataRequestException: Execution of request failed: 
http://www.google.com/m8/feeds/contacts/<UserEmailAddress>/full ---> 
System.Net.WebException: The remote server returned an error: (401) 
Unauthorized.

Can you tell me where I'm going wrong?

Also, I'm certain this was working with my prototype, maybe its not working 
since I downloaded later versions of the client library?

David S


-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Reply via email to