2016-04-07 41 views
0

我正在尝试使用Google.GData.Contacts Api在c#中将事件添加到Google Apps联系人。将事件插入到C#中的应用程序联系人#

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

您可能当您的令牌过期时遇到错误。一旦你刷新了令牌,一切都应该正常工作。你得到你的令牌刷新和手动重新使用的问题这个片段插入电话:

try{ 
    cr.Insert(feedUri,newContact); 
} 
catch(System.Net.ProtocolViolationException) 
{ 
    cr.Insert(feedUri,newContact); 
} 

入住此相关SO ticket。希望这可以帮助!

+0

我试过这个,但它不工作。 – Renuka

+0

如果我尝试添加事件联系,然后只有它会抛出异常及其不ProtocolViolationException。 – Renuka

相关问题