Google.GData.Contacts将联系人添加到Gapps
本文关键字:添加 Gapps 联系人 GData Contacts Google | 更新日期: 2023-09-27 18:36:05
我正在尝试将联系人添加到Gapps联系人。我尝试了下面的代码。它成功地将联系人添加到Google帐户,没有任何错误。但它不会在帐户中显示添加的联系人。这是我添加联系人的代码
'
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = clientId,
ClientSecret = clientSecret
},
Scopes = new string[] { "http://www.google.com/m8/feeds/" },
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
var token = credential.Token.AccessToken;
string RedirectURI = "urn:ietf:wg:oauth:2.0:oob";
OAuth2Parameters parameters = new OAuth2Parameters
{
ClientId = clientId,
ClientSecret = clientSecret,
// Note: AccessToken is valid only for 60 minutes
AccessToken = token,
RefreshToken = credential.Token.RefreshToken,
RedirectUri = RedirectURI
};
RequestSettings settings = new RequestSettings(
"AppName", parameters);
ContactsRequest cr = new ContactsRequest(settings);
Contact newContact = new Contact();
newContact.Name = new Name()
{
FullName = "Elizabeth Bennet",
GivenName = "Elizabeth",
FamilyName = "Bennet",
};
newContact.Content = "Notes";
// Set the contact's e-mail addresses.
newContact.Emails.Add(new EMail()
{
Primary = true,
Rel = ContactsRelationships.IsHome,
Address = "something@gmail.com"
});
newContact.Emails.Add(new EMail()
{
Rel = ContactsRelationships.IsWork,
Address = "something@gmail.com"
});
newContact.Location = "Pune";
Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
Contact createdContact = cr.Insert(feedUri, newContact); // Is Successfull
}`
当我获取联系人时,它会在结果中为我添加联系人。请提出问题的解决方案。
string str = createdContact.Id;
Feed<Contact> f = cr.GetContacts();
foreach (Contact c in f.Entries)
{
Console.WriteLine(c.Name.FullName);
}
谢谢;雷努卡。
您可以通过发送GET请求来检索所有联系人,但在此之前,您需要使用OAuth 2.0请求访问权限。应用程序需要范围信息。请注意您使用 Google 通讯录 API 发送的每个请求,指定版本号,使用 GData-Version HTTP 标头。Google Contacts API 的第 1 版和第 2 版已正式弃用。我们建议您使用版本 3。API 版本 3 为联系人姓名和结构化邮政地址字段引入了新的结构化数据格式有关联系人条目的更多详细信息,请点击此链接:https://developers.google.com/google-apps/contacts/v3/#contact_entry