Dropbox API 400 Error: “4xx Error (4xx) We can't find the page you're looking for.”

Dropbox API 400 Error: “4xx Error (4xx) We can't find the page you're looking for.”

我正在开发代表用户与 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.[=12)会发生这种情况=]

知道这是怎么回事吗?我以前没见过这个错误,所以我觉得有点混乱。

编辑:通过一些进一步的测试,当我调用 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 );
}

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

所以我刚刚添加:

curl_setopt( $ch, CURLOPT_POSTFIELDS, '' );

这似乎起到了作用。