使用Google Contacts .NET API添加联系人

时间:2010-04-27 01:05:57

标签: .net xamarin.ios contacts google-api

我使用以下代码添加联系人,但是我得到以下未处理的异常:      Google.GData.Client.GDataRequestException:执行请求失败:http://www.google.com/m8/feeds/contacts/default/full

        GDataCredentials myCred = new GDataCredentials("myusername", "mypassword");
        RequestSettings myRequestSettings = new RequestSettings("macpapa-GoogleCodeTest3-1", myCred);
        ContactsRequest myContactRequest = new ContactsRequest(myRequestSettings);

        Contact myContact = new Contact();
        myContact.Title = "Be Dazzle";
        PhoneNumber myPhoneNumber = new PhoneNumber("805-453-6688");
        myPhoneNumber.Rel = ContactsRelationships.IsGeneral;
        myPhoneNumber.Primary = true;
        myContact.Phonenumbers.Add(myPhoneNumber);

        EMail myEmail = new EMail("man@gmail.com", ContactsRelationships.IsHome);
        EMail myEmail2 = new EMail("mantest@gmail.com", ContactsRelationships.IsWork);
        myEmail.Primary = true;
        myContact.Emails.Add(myEmail);
        myContact.Emails.Add(myEmail2);

        PostalAddress postalAddress = new PostalAddress();
        postalAddress.Value = "123 somewhere lane";
        postalAddress.Primary = true;
        postalAddress.Rel = ContactsRelationships.IsHome;
        myContact.PostalAddresses.Add(postalAddress);


        Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
        Contact createdContact = myContactRequest.Insert<Contact>(feedUri, myContact);

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

可能是Google API的Monotouch(基于Mono)问题;见this帖子。

答案 1 :(得分:0)

这可能与您的联系人包含电子邮件地址有关:请参阅this question。删除myContact.Emails.Add行有帮助吗?如果没有,删除所有myContact.Xxx.Add行有帮助吗?