如何使用Google Drive API修复错误403 Google Drive可共享链接

时间:2019-05-04 09:50:05

标签: php google-drive-api google-drive-team-drive

我无法弄清楚,但是如果只有一个Google帐户登录浏览器,我的代码就可以正常工作,但是如果有一个以上的登录帐户,则可共享链接将显示错误403

function anyone($id, $token)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/$id/permissions?key=$token");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Content-type: application/json",
        "Authorization: Bearer $token",
        "{\"role\":\"reader\",\"type\":\"anyone\"}"
    ));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"role\":\"reader\",\"type\":\"anyone\"}");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

有人可以告诉我如何解决此问题吗?

0 个答案:

没有答案