dongshicuo4844 2014-11-14 17:29
浏览 25

编辑“未找到”中的联系人结果

I have working PHP code to create a Google contact via their v3 API. However, when it comes time to edit (update) the contact I cannot seem to get it to do the update. I keep getting a "Not Found" back in the update response. Any ideas why???

Here is my code.

$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);

Here is a var_dump of my request (data masked with 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
}

Here is a var_dump of my response:

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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c