2012-04-28 10 views
6

staram ti zintegrować z Google Gmail kontaktów śledzę ten przykład Google Contacts API version 3.0 mam ten błąd wykonanie żądania nie powiodło się: https://www.google.com/m8/feeds/contacts/default/fulljak stworzyć kontakt Google?

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

oczekiwanie wewnętrzna:

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

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

pełny kod

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 

Odpowiedz

7

Przykładowy kod Google wydaje się być nieprawidłowy. Zgodnie z dokumentacją Google Data type/kind gd:im requires the property address to be populated.

@address

@label?

@rel?

@protocol?

@primary?

konwencje:

elementName Required element

elementName ? Optional element

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

musisz zaktualizować część kodu, takich jak:

newEntry.IMs.Add(new IMAddress() 
{ 
    Address = "[email protected]", // untested 
    Primary = true, 
    Rel = ContactsRelationships.IsHome, 
    Protocol = ContactsProtocols.IsGoogleTalk, 
}); 
+1

ów praca dziękuję ,, myślę, że e-mail jest źle –

4

Problemem jest natomiast dodanie IM wejściem styku sugerowane przez Erik powyżej ... W przykładzie google api pominięto wymienienie adresu IM

wystarczy dodać address = "[email protected]" do folllowing

// Set the contact's IM information. 
    newEntry.IMs.Add(new IMAddress() 
     { 
      Primary = true, 
      Rel = ContactsRelationships.IsHome, 
      Protocol = ContactsProtocols.IsGoogleTalk, 
      **Address = "[email protected]",** 
     });