【问题标题】:Google Drive API files:COPY returns 404 errorGoogle Drive API 文件:COPY 返回 404 错误
【发布时间】:2022-01-20 10:59:31
【问题描述】:

当我成功运行“https://www.googleapis.com/drive/v3/files”时

但是,如果我尝试“https://www.googleapis.com/drive/v3/files/{fileId}/copy”,它会返回 404 错误

同样的例子,如果我尝试“Drive Explorer Try Now”,它也可以正常工作。那到底是怎么回事,想不通

$url = 'https://www.googleapis.com/drive/v3/files/1ZYyl0MzfWy_V5Io3N0BTsF19pNiX7s23BqYPbQKplvU/copy';   

$ch = curl_init();      
curl_setopt($ch, CURLOPT_URL, $url);        
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));
$data = json_decode(curl_exec($ch), true);

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);     

if($http_code != 200) 
    throw new Exception('Error : Failed');
    
return $data;

【问题讨论】:

  • 您只包含了 GET 的代码,我可以看到您的复制方法的代码吗?

标签: php curl google-drive-api google-docs google-docs-api


【解决方案1】:

404 not found 只是表示你尝试的终点没有找到。

但是您的副本不起作用,并且您说您已经检查过它与我所做的文件相同。

我想知道 Copy 是一个 http Post 请求,您忘记将其作为帖子发送了吗?

curl_setopt($ch, CURLOPT_POST, 1);

【讨论】:

  • 谢谢它解决了我的问题....有时不知道,忘记了简单的简单的东西...没注意到....谢谢,我添加了 curl_setopt($ch, CURLOPT_POST , 1);这条线和 COPY 工作正常!干杯
  • 很高兴它有帮助,如果有帮助请记得接受答案。您的声誉也会提高
猜你喜欢
  • 2017-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-16
  • 2017-10-21
  • 1970-01-01
  • 2014-11-01
  • 1970-01-01
相关资源
最近更新 更多