Редактирование результатов контакта в & quot; Не найдено & quot;

У меня есть рабочий код PHP для создания контакта Google через API v3. Однако, когда приходит время редактировать (обновлять) контакт, я не могу заставить его выполнить обновление. Я продолжаю получать «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 моего запроса (данные замаскированы с ххх):

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)
}

1

Решение

поскольку https://developers.google.com/google-apps/contacts/v3/http-update,
это означает, что запрос к API Контактов должен быть отправлен с помощью https: // вместо http: // сейчас, если вы заметили, что используете

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

скорее, чем

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

в var_dump моего кода запроса.

0

Другие решения

Я думаю, что вам нужно изменить

$request->setRequestMethod("POST");

в

$request->setRequestMethod("PUT");
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector