【发布时间】:2018-10-05 17:09:04
【问题描述】:
我正在使用 PeopleService 直接在我的 G Suit 帐户中创建联系人。我遵循了有关获取某种服务帐户的密钥的安全步骤。我的应用程序将创建联系人,因此无需请求特定的用户权限。它有自己的密钥和凭据。 我的代码似乎工作,除了因为 CreateContactRequest 为我提供了值为“people/c171255166120767303”的 ResourceName。每次我请求时,我都会得到一个不同的资源名称,例如“people/c9013378989213012841”。 问题是,这到底去哪儿了?在我的 G Suite 帐户中,我无法在任何地方看到创建的联系人。 但生成的 Person 对象似乎没问题。
如何检查这是否有效?联系人是在哪里创建的?
代码如下:
private static string _clientId = "1........1";
private static string _clienteScret = "i******************_";
private static string _serviceAccountId = "aaaa@bbbb.iam.gserviceaccount.com";
公共静态无效地籍(Models.SignupRequest 消息) {
var chave =
@"D:\********.p12";
var certificate = new X509Certificate2(chave, "notasecret", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(_serviceAccountId)
{
Scopes = new[] {
PeopleService.Scope.Contacts,
PeopleService.Scope.ContactsReadonly,
"https://www.google.com/m8/feeds"
}
}.FromCertificate(certificate));
var service = new PeopleService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Client for www",
});
var contactToCreate = new Person();
var names = new List<Name> {new Name() {GivenName = message.name, FamilyName = "Doe"}};
contactToCreate.Names = names;
contactToCreate.EmailAddresses = new List<EmailAddress>
{
new EmailAddress()
{
DisplayName = message.name,
Value = message.email
}
};
contactToCreate.Organizations = new List<Organization>
{
new Organization()
{
Current = true,
Name = message.nome_fantasia,
}
};
contactToCreate.Biographies = new List<Biography>
{
new Biography()
{
Value = message.ToString()
}
};
contactToCreate.PhoneNumbers = new List<PhoneNumber>
{
new PhoneNumber()
{
Type = "mobile",
Value = message.celular
},
new PhoneNumber()
{
Type = "work",
Value = message.telefone
}
};
var request = new Google.Apis.PeopleService.v1.PeopleResource.CreateContactRequest(service, contactToCreate);
var createdContact = request.Execute();
}
【问题讨论】:
标签: c# google-api google-api-client google-api-dotnet-client google-people-api