我正在尝试使用 php 和 curl 将文件上传到我的谷歌驱动器帐户。我不想要所有这些长身份验证流程的东西。为此,我实现了下面的代码
$secret ="xxxxxx";
$clientid ="xxxxxxx";
$ch = curl_init ();
curl_setopt_array ( $ch, array (
CURLOPT_URL => "https://www.googleapis.com/upload/drive/v3/files?uploadType=media&clientID=xxxxxxx&secret=xxxxxxx",
CURLOPT_HTTPHEADER => array (
'Content-Type: image/png'),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => file_get_contents ('iconc.png' ),
CURLOPT_RETURNTRANSFER => 1
) );
$res = curl_exec($ch);
$err = curl_error($ch);
echo $res;
var_dump($res);
echo "<br>";
echo "<br>";
echo $err ;
我已经启用了我的 google Drive Api 并且我已经分配了客户端 ID和密码,但是当我运行代码时,它说凭据无效,如下所示
{ "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" } } string(238) "{ "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" } } "
请问我在哪里传递上面代码中的客户端ID和密码,或者我是否需要访问令牌之类的东西。如果是,我从哪里获得谷歌驱动器 API 访问令牌。欢迎任何解决方案。谢谢
阿晨1998