我正在尝试使用Google.GData.Contacts cpi将事件添加到Google Apps联系人。
When objwhen = new When();
String objwhen1 = (year + "-" + month + "-" + day);
var nowString = dt.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true);
DateTime dateVal = DateTime.ParseExact(objwhen1, "yyyy-MM-dd", null, System.Globalization.DateTimeStyles.None);
objwhen.StartTime = dt.ToUniversalTime();
string str = objwhen.StartTime.ToString();
newContact.ContactEntry.Events.Add(new Google.GData.Contacts.Event()
{
Relation = "anniversary",
When = objwhen,
Label = "Anniversary"
});
到此为止,没有错误或例外,但插入联系人时
createdContact = contactRequest.Insert(feedUri, newContact);
抛出异常: 执行请求失败:https://www.google.com/m8/feeds/contacts/default/full
请建议solutin
答案 0 :(得分:0)
令牌过期时可能会遇到错误。刷新令牌后,一切都应该正常。您可以使用此代码段刷新令牌并手动重新发出插入调用:
try{
cr.Insert(feedUri,newContact);
}
catch(System.Net.ProtocolViolationException)
{
cr.Insert(feedUri,newContact);
}
检查此相关SO ticket。希望这有帮助!