通过Google通讯录API更新联系人时出现错误请求

时间:2013-12-02 18:37:39

标签: c# winforms c#-4.0 google-contacts google-profiles-api

目前我正在开发一款应用,通过google contacts api添加和更新联系人。

它到目前为止有效,但我在更新程序中遇到了问题..

我的工作流程是:

获取特定联系人,编辑/添加一些属性,然后将其更新为Google ..

但是当我尝试向联系人添加新的电子邮件地址时,我收到“远程服务器返回错误:(400)错误请求。”回错。内部异常为空。

ContactsRequest cr = new ContactsRequest(new RequestSettings(CStr.Caption, new       GDataCredentials(Username, Password)));
Contact newEntry = new Contact();

//retrieve original contact
// First, retrieve the contact to update.
Contact contact = cr.Retrieve<Contact>(new Uri(GoogleTargetId));

//check each field like phone, mail, address, etc.
foreach(CollisionField field in list)
{
           switch(field.collisionField)
           {
                    case CollisionFieldEnum.Mail:
                    //Should this field be synced?
                    if (field.Sync)
                    {
                        try
                        {
                            //may be there is already an existing email address?

                            EMail e = contact.Emails.FirstOrDefault(
                                x => x.Value == GoogleOrig.Mail);
                            if (e != null)
                                e.Value = SourceContact.Mail;
                            else
                            {
                                //no email found, so add a new one
                                e = new EMail()
                                {
                                    Primary = true,
                                    Value = SourceContact.Mail,
                                    Rel = ContactsRelationships.IsHome
                                };
                                //add this email to the collection
                                contact.Emails.Add(e);
                            }
                            field.Synced = true;
                        }
                        catch(Exception ex)
                        {
                            CMisc.AttachToLog("Cannot update Google Contact field: " + field.collisionField.ToString() + "; " + ex.ToString());
                            field.Synced = false;
                        }
                    }
                    break;
                //some more fields like phone, mobile, address, etc...
                default:
                    break;

远没有问题......

我在这里得到了例外,当我想要提交更改时:

Contact updatedC = cr.Update(contact);

向联系人添加新电子邮件地址时,我只遇到此问题。电话,地址等完美无缺......但不是邮件。

现在我没有任何线索如何解决这个问题。 可能有人可以帮我解决这个问题。 如果您需要更多信息,请告诉我,我会发布它。

提前致谢..

0 个答案:

没有答案
相关问题