Authenticate and Add Contacts to GMail Account VB.Net

1,483 views
Skip to first unread message

HK1

unread,
Oct 7, 2011, 10:16:12 PM10/7/11
to Google Contacts, Shared Contacts and User Profiles APIs
I'm trying to build a simply desktop application in VB.Net to import
contacts into Google/Gmail Contacts. I've been reading everything I
can to try to understand how to authenticate and add contacts but I
remain horribly confused.

If I had something that was partially working I would post it here
along with any error messages but I don't even have anything like that
yet. I'm wondering if anyone can get me pointed in the right
direction. I'm using the Google GData API Version: 1.9.0.0 and I'm
trying to authenticate using ClientLogin. Any help would be very
appreciated.

HK1

unread,
Oct 8, 2011, 8:58:36 AM10/8/11
to Google Contacts, Shared Contacts and User Profiles APIs
Late last night I finally pieced something together that works
(working code posted below). However, I still have many unanswered
questions. Here's a few of them.

1) How do I retrieve the login message or the capcha during a login
failure?

2) How can I save and reuse the token. How long with the token last?
Is there some way I can check to see if I'm logged in or not. I admit
the whole login thing has me fairly confused.

3) How can I retrieve an error message in the event that inserting the
contact fails?



Dim conserv As New ContactsService("MyCompany-MyApp-v1.0")
Dim authFactory As New GDataGAuthRequestFactory("cp",
"MyCompany-MyApp-v1.0")
authFactory.AccountType = "GOOGLE"

conserv.RequestFactory = authFactory
conserv.setUserCredentials("your...@gmail.com",
"YourPassword")
conserv.QueryClientLoginToken()

Dim nc As New ContactEntry

With nc
.Name = New Google.GData.Extensions.Name()
.Name.FullName = "John Davis"
.Name.GivenName = "John"
.Name.FamilyName = "Davis"
End With

Dim org As New Google.GData.Extensions.Organization()
With org
.Rel =
Google.GData.Extensions.ContactsRelationships.IsWork
.Name = "Garfield"
.Primary = True
End With

nc.Organizations.Add(org)

Dim ph As New
Google.GData.Extensions.PhoneNumber("111-222-3333")
With ph
.Primary = True
.Rel =
Google.GData.Extensions.ContactsRelationships.IsWork
'I'm not sure when you need to use this
'.Uri = "tel:+1111222333"
End With
nc.Phonenumbers.Add(ph)

Dim urifeed As New
Uri(ContactsQuery.CreateContactsUri("default"))
conserv.Insert(urifeed, nc)

Alain Vongsouvanh

unread,
Oct 10, 2011, 3:36:33 AM10/10/11
to google-co...@googlegroups.com
Hello,

If your application needs the user to authorize the requests sent to the API (which is the case of Google Contacts API), please use OAuth instead of ClientLogin as it lets users grant access without having to give away their login & password.

For installed applications, there are 2 choices:
  * Have the application listen on a port for a redirect from our authorization server: once the user grants access, our server redirects the user to the provided redirect URI which can be localhost.
  * Ask the authorization to provide a code that the user can copy & paste into your application.

An OAuth token is usually long lived and should work until the users decide to revoke access in their issued tokens console. The best way to check if the token works is to surround all your API calls with try/catch blocks and check for HTTP 403 status code as a token can be revoked at any time.

Best,
Alain


--
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
google-co...@googlegroups.com
To unsubscribe from this group, send email to
google-contacts...@googlegroups.com
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html



--
Alain Vongsouvanh | Developer Programs Engineer
Reply all
Reply to author
Forward
0 new messages