【问题标题】:Google People Api Contact is created but I can't see it anywhereGoogle People Api 联系人已创建,但我在任何地方都看不到它
【发布时间】: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


    【解决方案1】:

    如果您想通过您需要的服务帐户使用“email@yourdomain.com”为用户创建联系人:

    • 使用“setServiceAccountUser(userEmail)”冒充用户
    • 在您的 G-Suite for People API 服务上启用模拟。对于这一点:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多