【发布时间】:2017-10-31 00:28:18
【问题描述】:
我正在尝试使用下面的代码通过 google people api + PHP(服务器到服务器)创建一个新联系人,代码显然运行没有错误,但没有在以下位置创建联系人:https://www.google.com/contacts/
按照此处所述查询联系人 (https://developers.google.com/people/quickstart/php#step_3_set_up_the_sample) 我看到联系人已创建。
我使用 Google App Suite。
我的代码有什么问题吗?
<?php
require $_SERVER['DOCUMENT_ROOT'].'/../vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('my configs...');
$client->addScope(Google_Service_PeopleService::CONTACTS);
$service = new Google_Service_PeopleService($client);
$person = new Google_Service_PeopleService_Person();
$email = new Google_Service_PeopleService_EmailAddress();
$email->setValue('test@test.com');
$person->setEmailAddresses($email);
$name = new Google_Service_PeopleService_Name();
$name->setDisplayName('User de Test');
$person->setNames($name);
$exe = $service->people->createContact($person);
print_r($exe);
【问题讨论】:
-
Is there anything wrong with my code?你告诉我们。脚本有效吗?有什么错误吗?它有什么问题? -
您首先需要代表您的应用与 google 创建一个 OAUTH 会话,以便在您的帐户上创建联系人。如果您使用的是服务帐户 ( two-legged-oauth ),然后在不先创建会话的情况下添加联系人,它可能被保存在服务帐户范围内
标签: php google-api