Dropbox API 400错误:“4xx错误(4xx)我们无法找到您正在寻找的页面。”

时间:2017-04-28 03:15:44

标签: php dropbox-api

我正在开发一个代表用户与Dropbox通信的PHP脚本。

在我自己的系统上一切正常。但是在某个用户的系统上,我们得到了这个非常神秘的错误,如下:

Error: DropBox API: (400) Bad input parameter: Dropbox - 4xx Error (4xx) We can't find the page you're looking for. Here are a few links that may be helpful: Home Help center Sign in Get a free account Dropbox Plus Dropbox Business message = {"ru": "..."}

大括号中的部分是几种语言的JSON字符串,它只显示一堆HTML,其中包含指向主页,注册等的链接。

只有在上传大文件时才会发生这种情况,所以我相信它会发生一个API请求,例如files / upload_session / start或files / upload_session / append_v2。

知道这可能是什么来的吗?我之前没有看到过这个错误所以我觉得它有点令人困惑。

编辑:通过一些进一步的测试,当我调用files / upload_session / start时会发生这种情况。没有参数发送,API报告此调用不会发生任何错误。

编辑2:这里有一些示例代码,演示了如何进行通话。没有数据发送到files / upload_session / start。这绝对是导致它失败的电话。

$ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/upload_session/start' );
    curl_setopt( $ch, CURLOPT_POST, true );

$headers[] = 'Expect:';
    $headers[] = 'Authorization: Bearer ' . $this->oauth_token['access_token'];
    $headers[] = 'Content-Type: application/octet-stream';

curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_HEADER, true );
if ( 0 == curl_errno( $ch ) ) {
    $response = explode( "\r\n\r\n", curl_exec( $ch ), 2 );
}

1 个答案:

答案 0 :(得分:2)

我终于解决了这个问题。基本上,因为我没有发送帖子正文,该特定用户的系统发送的Content-Length为-1。我仍然不确定为什么 - 不确定它是否是因为PHP的版本或其他东西 - 但这就是发生的事情。在我自己的系统上,以及大多数其他用户,它正确地处理它。

所以我刚补充说:

curl_setopt( $ch, CURLOPT_POSTFIELDS, '' );

这似乎可以解决问题。