Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create google contact?

Tags:

c#

i'm trying ti integrate with google gmail contacts i follow this example Google Contacts API version 3.0 i got this error Execution of request failed: https://www.google.com/m8/feeds/contacts/default/full

Google.Contacts.Contact createdEntry = cr.Insert(feedUri, newEntry);

Inner expectation:

{"The remote server returned an error: (400) Bad Request."}

[Line 12, Column 127, element gd:im] Missing attribute: 'address'

the full code

using Google.Contacts;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;



            RequestSettings settings = new RequestSettings("OVI2GoogleContacts", "my email", "pass");
        ContactsRequest cr = new ContactsRequest(settings);

        Google.Contacts.Contact newEntry = new Google.Contacts.Contact();

        // Set the contact's name.
        newEntry.Name = new Name()
            {
                FullName = "Elizabeth Bennet",
                GivenName = "Elizabeth",
                FamilyName = "Bennet",
            };
        newEntry.Content = "Notes";
         //Set the contact's e-mail addresses.
        newEntry.Emails.Add(new EMail()
            {
                Primary = true,
                Rel = ContactsRelationships.IsHome,
                Address = "liz<at>gmail.com"
            });
        newEntry.Emails.Add(new EMail()
            {
                Rel = ContactsRelationships.IsWork,
                Address = "liz<at>example.com"
            });
         //Set the contact's phone numbers.
        newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Primary = true,
                Rel = ContactsRelationships.IsWork,
                Value = "(206)555-1212",
            });
        newEntry.Phonenumbers.Add(new PhoneNumber()
            {
                Rel = ContactsRelationships.IsHome,
                Value = "(206)555-1213",
            });
        // Set the contact's IM information.
        newEntry.IMs.Add(new IMAddress()
            {
                Primary = true,
                Rel = ContactsRelationships.IsHome,
                Protocol = ContactsProtocols.IsGoogleTalk,
            });
        // Set the contact's postal address.
        newEntry.PostalAddresses.Add(new StructuredPostalAddress()
            {
                Rel = ContactsRelationships.IsWork,
                Primary = true,
                Street = "1600 Amphitheatre Pkwy",
                City = "Mountain View",
                Region = "CA",
                Postcode = "94043",
                Country = "United States",
                FormattedAddress = "1600 Amphitheatre Pkwy Mountain View",
            });
        // Insert the contact.
        Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
        Google.Contacts.Contact createdEntry = cr.Insert(feedUri, newEntry); // here the error
like image 345
Khalid Omar Avatar asked Apr 28 '12 14:04

Khalid Omar


2 Answers

Google's own sample code appears to be invalid. According to the documentation Google Data type/kind gd:im requires the property address to be populated.

@address

@label?

@rel?

@protocol?

@primary?

Conventions:

elementName Required element

elementName ? Optional element

elementName ***** Optional element, multiple instances allowed

You'll need to update a part of the code like:

newEntry.IMs.Add(new IMAddress()
{
  Address = "[email protected]",  // untested
  Primary = true,
  Rel = ContactsRelationships.IsHome,
  Protocol = ContactsProtocols.IsGoogleTalk,
});
like image 162
Erik Philips Avatar answered Oct 06 '22 19:10

Erik Philips


The problem is while adding IM to the contact entry as suggested by Erik above... In the google api example, they have missed mentioning the IM Address

just add Address = "[email protected]", to folllowing

    // Set the contact's IM information.
    newEntry.IMs.Add(new IMAddress()
        {
            Primary = true,
            Rel = ContactsRelationships.IsHome,
            Protocol = ContactsProtocols.IsGoogleTalk,
            **Address = "[email protected]",**
        });
like image 36
RiteshR Avatar answered Oct 06 '22 20:10

RiteshR