How to create a google contact?

I'm trying to integrate integration with google gmail contacts, following this example the Google Contacts 3.0 API , I got this error The request failed: https://www.google.com/m8/feeds/contacts/default/full

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

Internal waiting:

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

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

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 name. newEntry.Name = new Name() { FullName = "Elizabeth Bennet", GivenName = "Elizabeth", FamilyName = "Bennet", }; newEntry.Content = "Notes"; //Set the contact 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 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 IM information. newEntry.IMs.Add(new IMAddress() { Primary = true, Rel = ContactsRelationships.IsHome, Protocol = ContactsProtocols.IsGoogleTalk, }); // Set the contact 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 
+6
source share
2 answers

Native example of Google code is not valid. According to the documentation Google Type / Data Type gd: im requires the property address to be populated .

@address

@label?

@rel?

@protocol?

@primary?

Legend:

elementName Required element

elementName ? Optional element

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

You will need to update part of the code, for example:

 newEntry.IMs.Add(new IMAddress() { Address = " email@dot.com ", // untested Primary = true, Rel = ContactsRelationships.IsHome, Protocol = ContactsProtocols.IsGoogleTalk, }); 
+7
source

The problem is adding IM to the contact record, as suggested by Eric above ... In the Google api example, they missed the mention of the IM address

just add Address = " liz@gmail.com " , to do the following

  // Set the contact IM information. newEntry.IMs.Add(new IMAddress() { Primary = true, Rel = ContactsRelationships.IsHome, Protocol = ContactsProtocols.IsGoogleTalk, **Address = " liz@gmail.com ",** }); 
+4
source

Source: https://habr.com/ru/post/914417/


All Articles