[英]Create Contact with Google People API + PHP (Server to Server)
I'm trying to create a new contact through google people api + PHP (Server-to-server) using the code below and the code apparently runs without errors, but no contacts are created at: https://www.google.com/contacts/我正在尝试使用下面的代码通过 google people api + PHP(服务器到服务器)创建一个新联系人,代码显然运行没有错误,但没有在以下位置创建联系人: https : //www.google.com /联系人/
Querying the contacts as described here ( https://developers.google.com/people/quickstart/php#step_3_set_up_the_sample ) I see that the contact was created.按照此处所述查询联系人 ( https://developers.google.com/people/quickstart/php#step_3_set_up_the_sample ) 我看到联系人已创建。
I use Google App Suite.我使用 Google 应用套件。
Is there anything wrong with my code?我的代码有什么问题吗?
<?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);
i think you should try this php library it did the same task for me https://github.com/rapidwebltd/php-google-contacts-v3-api我想你应该试试这个 php 库,它为我做了同样的任务https://github.com/rapidwebltd/php-google-contacts-v3-api
Installation :-安装:-
-download the repo git clone https://github.com/rapidwebltd/php-google-contacts-v3-api
- 下载 repo
git clone https://github.com/rapidwebltd/php-google-contacts-v3-api
-then run composer require rapidwebltd/php-google-contacts-v3-api
- 然后运行
composer require rapidwebltd/php-google-contacts-v3-api
-create api credential on google api here https://console.developers.google.com/ -在此处在 google api 上创建 api 凭据https://console.developers.google.com/
-then rename the .config_blank.json
to .config.json
and update the clientID
, clientSecret
to the credential you get from the api console - 然后将
.config_blank.json
重命名为.config.json
并将clientID
、 clientSecret
更新为您从 api 控制台获得的凭据
-update the redirectUri
in the .config.json file to the full path to your redirect-handler.php
file -Update的
redirectUri
在.config.json文件的完整路径redirect-handler.php
文件
-then go ahead and open authorise-application.php
in your browser & open the provided link in a new tab to authorize your app then this page will redirect you to the file redirect-handler.php
and will ask you to add the hash providedd to the .config.json
file for the attribute refreshToken
- 然后继续在浏览器中打开
authorise-application.php
并在新选项卡中打开提供的链接以授权您的应用程序然后此页面会将您重定向到文件redirect-handler.php
并要求您添加提供的哈希到属性refreshToken
的.config.json
文件
-done you can try this code to create new contact in your account - 完成后,您可以尝试使用此代码在您的帐户中创建新联系人
require_once __DIR__ . '/vendor/autoload.php';
$contact->name = 'Test';
$contact->phoneNumber = '07812363789';
$contact->email = 'test@example.com';
$contact->content = 'Note for example';
$contactAfterUpdate =rapidweb\googlecontacts\factories\ContactFactory::submitUpdates($contact);
var_dump($contactAfterUpdate);
Update:更新:
as DivineOmega 's comment there is a new version of the API Here you can try it.正如DivineOmega的评论,有一个新版本的 API在这里你可以试试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.