编辑未找到的联系人结果"

时间:2014-11-14 17:29:30

标签: php api contacts edit google-contacts

我使用PHP代码通过他们的v3 API创建Google联系人。但是,当需要编辑(更新)联系人时,我似乎无法让它进行更新。我在更新响应中不断收到“Not Found”。任何想法为什么???

这是我的代码。

$client  = new Google_Client();

$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(SCOPE);
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URI);
$client->setAccessToken($token);

$xml = <<<END_XML
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:gContact='http://schemas.google.com/contact/2008'>
   <atom:content type='text'>{$content}</atom:content>
</atom:entry>
END_XML;

$request = new Google_Http_Request("https://www.google.com/m8/feeds/contacts/{$account}/full/{$contact['id']}");
$request = $client->getAuth()->sign($request);
$request->setRequestMethod("POST");
$request->setPostBody($xml);
$request->setRequestHeaders(array('content-length' => strlen($xml), 'GData-Version'=> '3.0','content-type'=>'application/atom+xml; charset=UTF-8; type=feed'));

$response    = $client->getIo()->executeRequest($request);

以下是我的请求的var_dump(使用xxx屏蔽的数据):

object(Google_Http_Request)#5 (14) {
  ["batchHeaders":"Google_Http_Request":private]=>
  array(3) {
    ["Content-Type"]=>
    string(16) "application/http"
    ["Content-Transfer-Encoding"]=>
    string(6) "binary"
    ["MIME-Version"]=>
    string(3) "1.0"
  }
  ["queryParams":protected]=>
  array(0) {
  }
  ["requestMethod":protected]=>
  string(4) "POST"
  ["requestHeaders":protected]=>
  array(4) {
    ["authorization"]=>
    string(90) "Bearer ya29.vQDJSs7ZxzBG8eN05Er6KiwutMf0K_uNKyuNUu4s5jd9XL4oA3o_SsikhUeIGzRoVtacYwlVVFcEYg"
    ["content-length"]=>
    int(392)
    ["gdata-version"]=>
    string(3) "3.0"
    ["content-type"]=>
    string(46) "application/atom+xml; charset=UTF-8; type=feed"
  }
  ["baseComponent":protected]=>
  string(22) "https://www.google.com"
  ["path":protected]=>
  string(65) "/m8/feeds/contacts/events@xxx/full/1603b8310ac9f5ca"
  ["postBody":protected]=>
  string(392) "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:gContact='http://schemas.google.com/contact/2008'>
   <id>http://www.google.com/m8/feeds/contacts/events%40xxx/base/1603b8310ac9f5ca</id>
   <atom:content type='text'>Notes Test Data</atom:content>
</atom:entry>"
  ["userAgent":protected]=>
  NULL
  ["canGzip":protected]=>
  NULL
  ["responseHttpCode":protected]=>
  NULL
  ["responseHeaders":protected]=>
  NULL
  ["responseBody":protected]=>
  NULL
  ["expectedClass":protected]=>
  NULL
  ["accessKey"]=>
  NULL
}

这是我的回复的var_dump:

array(3) {
  [0]=>
  string(9) "Not Found"
  [1]=>
  array(12) {
    ["cache-control"]=>
    string(46) "no-cache, no-store, max-age=0, must-revalidate"
    ["pragma"]=>
    string(8) "no-cache"
    ["expires"]=>
    string(29) "Fri, 01 Jan 1990 00:00:00 GMT"
    ["date"]=>
    string(29) "Fri, 14 Nov 2014 00:13:58 GMT"
    ["vary"]=>
    string(15) "Origin
X-Origin"
    ["content-type"]=>
    string(24) "text/html; charset=UTF-8"
    ["x-content-type-options"]=>
    string(7) "nosniff"
    ["x-frame-options"]=>
    string(10) "SAMEORIGIN"
    ["x-xss-protection"]=>
    string(13) "1; mode=block"
    ["server"]=>
    string(3) "GSE"
    ["alternate-protocol"]=>
    string(15) "443:quic,p=0.01"
    ["transfer-encoding"]=>
    string(7) "chunked"
  }
  [2]=>
  int(404)
}

2 个答案:

答案 0 :(得分:0)

https://developers.google.com/google-apps/contacts/v3/http-update以来, 这意味着必须使用https://而不是http://发送对Contacts API的请求,您是否注意到您正在使用

http://www.google.com/m8/feeds/contacts/events%40xxx/base/1603b8310ac9f5ca

而不是

https://www.google.com/m8/feeds/contacts/events%40xxx/base/1603b8310ac9f5ca

在我的请求代码的var_dump中。

答案 1 :(得分:0)

我认为你需要改变

$request->setRequestMethod("POST");

$request->setRequestMethod("PUT");