Google Drive API推送通知订阅400;解析错误;


Google Drive API push notification subscription 400 "parse error"

我正在尝试订阅当Google Drive中的文件更改时获得推送通知。我已经成功地实现了Oauth2过程,并收到了一个访问令牌。

当我尝试订阅观看频道时,我得到一个解析错误,我认为这意味着我的请求正文中有一个错误…但是我不明白。

以下是我正在使用的几个google资源的链接:

https://developers.google.com/drive/v3/web/push

https://developers.google.com/drive/v3/reference/changes/watch

下面是我请求推送通知的代码(php):

    //subscribe to new watch channel
    $ch = curl_init("https://www.googleapis.com/drive/v3/files/1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx/watch");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                    'Authorization: Bearer '. $token["access_token"],
                    'Content-Type: application/json'
                ));
    $body_array = array(
                    "kind: api#channel", 
                    "id: ".generate_uuid(), // Your channel ID.
                    "resourceId: 1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx",
                    "resourceUri: https://docs.google.com/spreadsheets/d/1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx/",
                    "type: web_hook",
                    "address: http://exampmle.com/test/drivenotifications/receiver/index.php" // Your receiving URL.
                );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $body_array);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);

下面是错误响应:

"error": { "errors": [  {   "domain": "global",   "reason": "parseError",   "message": "Parse Error"  } ], "code": 400, "message": "Parse Error"}}
任何帮助/建议都是非常感谢的!<标题>编辑

我还尝试了每个注释的关联数组:

$body_array = array(
                    "kind"=>"api#channel", 
                    "id"=>generate_uuid(), // Your channel ID.
                    "resourceId"=>"1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx",
                    "resourceUri"=>"https://docs.google.com/spreadsheets/d/1fEDEciN1h_7MZJmNxmgUF-xxxxxxxxx/",
                    "type"=>"web_hook",
                    "address"=>"http://example.com/test/drivenotifications/receiver/index.php" // Your receiving URL.
                );

但是结果是相同的错误

您需要json_encode post数据。在$body _array上执行json_encode,在CURLOPT_POSTFIELDS上调用curl_setopt。在运行json_encode之前,确保$body_array是一个关联数组。