我无法使用google api v3在谷歌中创建联系人。
我可以成功致电cr.GetContacts()
以获取所有联系人(针对我指定的用户),但cr.Insert
正在给我错误:
执行请求失败:https://www.google.com/m8/feeds/contacts/someuser@mydomain.com/full
我错过了什么吗?
string serviceAccountEmail = "111111111111-aaaa1a1aa11a1aaaaaaa11aaaa1aaa11@developer.gserviceaccount.com";
X509Certificate2 certificate = new X509Certificate2(@"C:\All\ContactsManager-1aa1bbb1ab11.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[]
{
"https://www.google.com/m8/feeds"
},
User = "someuser@mydomain.com"
}.FromCertificate(certificate));
credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Wait();
RequestSettings rs = new RequestSettings("ContactsManager", credential.Token.AccessToken);
//rs.AutoPaging = true;
ContactsRequest cr = new ContactsRequest(rs);
//var contacts = cr.GetContacts(); //////THIS LINE WORKS AND GETS ALL THE CONTACTS
Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("someuser@mydomain.com"));
//feedUri will now be https://www.google.com/m8/feeds/contacts/someuser%40mydomain.com/full
Contact createdEntry = cr.Insert(feedUri, newContact);
Console.WriteLine("Contact's ID: " + createdEntry.Id);
答案 0 :(得分:1)
newEntry.IMs.Add(new IMAddress()
{
Primary = true,
Rel = ContactsRelationships.IsHome,
Protocol = ContactsProtocols.IsGoogleTalk,
});
如果删除此IMAddress,则联系人创建正常。