currently I'm working on an app, adding and updateting a contact via google contacts api.
It works so far, but I'm having an issue at the update procedure..
My workflow is this:
Get the specific contact, edit/add some properties, and update it to google..
But when I try to add a new email address to the contact, I get a "The remote server returned an error: (400) Bad Request." Error back. Inner Exception is null.
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;
o far no problems...
I get the exception right here, when I want so submit the changes:
Contact updatedC = cr.Update(contact);
I only have this problem when adding a new email address to the contact. Phone, Address, etc works all perfectly.. but not the mail.
Now I don't have any clues how to resolve this problem. May be someone could help me please with this issue. If you need some more informations, just let me know and I'll post it.
Thanks in advance..