【发布时间】:2019-06-04 00:38:56
【问题描述】:
我正在尝试通过 C# 中的联系人 API 在 GSuite 中创建域共享联系人,但无法弄清楚如何将 atom XML 条目发布到此处提到的 Feed URL:https://developers.google.com/admin-sdk/domain-shared-contacts/#Creating
我已尝试遵循此处提到的旧 GData 方式https://developers.google.com/gdata/client-cs,但我收到“执行身份验证请求返回意外结果:404”错误。
static void Main(string[] args)
{
Console.WriteLine("Hello !! ");
//Get Auth
OAuth2Parameters p = ContactsAuth();
//Create a domain shared contact
try
{
RequestSettings settings = new RequestSettings("GSuiteAdminApp", p);
ContactsRequest cr = new ContactsRequest(settings);
ContactEntry cn = new ContactEntry();
Name n = new Name();
n.GivenName = "Ice";
n.FamilyName = "Cold001";
n.FullName = "Ice Cold001";
EMail e = new EMail();
e.Rel = "http://schemas.google.com/g/2005#work";
e.Primary = true;
e.Address = "ice.cold001@xyz.com";
cn.Name = n;
cn.Emails.Add(e);
}
catch (Exception e44)
{
Console.WriteLine(e44.Message);
}
}
//Auth for Contacts API
public static OAuth2Parameters ContactsAuth()
{
string clientId = "xxxxxxxxxxxxxx.apps.googleusercontent.com";
string clientSecret = "xxxxxxxxxxxxx";
string[] scopes = new string[] { "https://www.google.com/m8/feeds/" };
try
{
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
ClientId = clientId,
ClientSecret = clientSecret
}, scopes, "super-admin@mydomain.com", CancellationToken.None, new FileDataStore("C:\\Temp\\A\\SharedContactsOauth")).Result;
// Translate the Oauth permissions to something the old client libray can read
OAuth2Parameters parameters = new OAuth2Parameters();
parameters.AccessToken = credential.Token.AccessToken;
parameters.RefreshToken = credential.Token.RefreshToken;
return parameters;
}
catch (Exception ex33)
{
Console.WriteLine(ex33.Message);
return null;
}
}
这会给出“请求失败”错误。
【问题讨论】:
-
您是否考虑过使用 People api。它应该为您提供相同的访问权限,并且您不必使用不再受支持的 gdata 库。
-
感谢琳达调查。我检查了 People API,但没有任何地方提到使用 API 创建“域共享联系人”。
标签: c# google-api google-contacts-api