如何在PHP中删除/更新/创建Google Contacts API

时间:2016-09-05 22:08:42

标签: php google-api google-api-php-client

我正在尝试Google通讯录API,我可以检索联系人,但我不明白如何使用API​​删除,创建或删除。我尝试了一个简单的形式,但我有一个错误401



<?php
  }else{
    $client->setAccessToken($_SESSION['token']);
    $token = json_decode($_SESSION['token']);
    var_dump($token->access_token);
    var_dump($client->getAccessToken());
    $curl = curl_init('https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=50&access_token='.$token->access_token);
    curl_setopt($curl , CURLOPT_RETURNTRANSFER , true);
    curl_setopt($curl , CURLOPT_SSL_VERIFYPEER , false);
    curl_setopt($curl , CURLOPT_TIMEOUT , 10);
    $contact_json = curl_exec($curl);
    var_dump($contact_json);
    curl_close($curl) ;
    $contacts = json_decode($contact_json , true);
    var_dump( $contacts['feed']['entry'][7]);
    $monContact = $contacts['feed']['entry'][7];
    $monContactId =  $monContact['id']['$t'];



  }
 ?>
 <form class="" action="<?= $monContactId?>" method="DELETE">
   <input type="submit" name="name" value="DELETE">
 </form>
&#13;
&#13;
&#13;

我尝试过这样但我不知道如何操作。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

你可以使用强大的类: https://github.com/rapidwebltd/php-google-contacts-v3-api

您可以检索所有类似的联系人:

rapidweb\googlecontacts\factories\ContactFactory::getAll()

或创建联系人:

$name = "Frodo Baggins";
$phoneNumber = "06439111222";
$emailAddress = "frodo@example.com";

$newContact = rapidweb\googlecontacts\factories\ContactFactory::create($name, $phoneNumber, $emailAddress);

有关详细信息,请查看此博文:http://www.rapidweb.biz/news/php-library-for-the-google-contacts-api-v3-06102593/