mercoledì 24 ottobre 2012

C# Google API - Edit Google Contact

After getting the contact could be usefull update them, for example adding/deleting o modifing info.
The following code shows a c# method to update the info about a single google contact, for example full name.

private Contact UpdateContactName(ContactsRequest cr, Uri contactURL)
            Contact contact = cr.Retrieve<Contact>(contactURL);

            //FOR Example Update The Full Name
            contact.Name.FullName = "New Full Name";

                Contact updatedContact = cr.Update(contact);
                return updatedContact;
            catch (GDataVersionConflictException e)
                //DO What You Want
            return null;

Here the building of the parameters to pass to the method

            GDataCredentials Credentials = new GDataCredentials("", "yourPassword");
            RequestSettings settings = new RequestSettings("AddressBook", Credentials);
            settings.UseSSL = true;

            ContactsRequest cr = new ContactsRequest(settings);
            Contact contatto = cr.Retrieve<Contact>(new Uri("Your Contact Uri"));

            UpdateContactName(cr, new Uri("Your Contact Uri"));

I want to remeber to go here to get  Application-specific password

and read here : to have "Contact Url"

My Two Cents...

Nessun commento:

Posta un commento