我让这段代码“工作”(阅读不抛出异常)。但是该联系人没有按应有的方式添加到我的 gmail 联系人中(也没有在我的同步联系人的 android 手机上)。
请注意,我可以正确读取联系人,因此凭据是正确的。
我读到我应该检查请求中的状态,但我看到的唯一状态是 ContactEntry 的一个属性,它始终为空。
这是一个用于测试的控制台应用程序。
public static void AddContact(ContactDetail contact)
{
GContactService = new ContactsService("Contact Infomation");
GContactService.setUserCredentials("myemail@gmail.com", "mypassword");
ContactEntry newEntry = new ContactEntry();
newEntry.Title.Text = contact.Name;
newEntry.Name = new Name() { FullName = "Tristan Savage", GivenName = "Tristan", FamilyName = "Savage"};
EMail primaryEmail = new EMail(contact.EmailAddress1);
primaryEmail.Primary = true;
primaryEmail.Rel = ContactsRelationships.IsWork;
newEntry.Emails.Add(primaryEmail);
PhoneNumber phoneNumber = new PhoneNumber(contact.Phone);
phoneNumber.Primary = true;
phoneNumber.Rel = ContactsRelationships.IsMobile;
newEntry.Phonenumbers.Add(phoneNumber);
PostalAddress postalAddress = new PostalAddress();
postalAddress.Value = contact.Address;
postalAddress.Primary = true;
postalAddress.Rel = ContactsRelationships.IsCompanyMain;
newEntry.PostalAddresses.Add(new StructuredPostalAddress() { City = "montreal", Label = "Bureau"});
newEntry.Content.Content = contact.Details;
Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default")); //default
ContactEntry createdEntry = (ContactEntry)GContactService.Insert(feedUri, newEntry);
}