无法使用 PHP 在 google api 请求中添加多个范围

Unable to Add Multiple scopes in google apis request using PHP

我正在研究 google api 并访问 google 驱动器日历等,同时请求单一范围,即 google 工作表或文档,它工作正常但无法在其中设置多个范围单个请求。

我尝试了其他论坛上讨论的各种事情,比如添加了多个 用逗号分隔添加了多个范围

$client->setScopes(Google_Service_Calendar::CALENDAR,Google_Service_Drive::DRIVE);

还创建了新数组,如

$scopes=['Google_Service_Calendar::CALENDAR','Google_Service_Drive::DRIVE']

但 none 对我有用

这是我的代码

$client = new Google_Client();
$client->setScopes(Google_Service_Calendar::CALENDAR,Google_Service_Drive::DRIVE);
$client->setAuthConfig('simplo_other_secret.json');
$client->setAccessType('offline');
$client->setPrompt('select_account consent');

任何帮助将不胜感激

我不是 PHP 专家,但是...

根据示例,setScopes 方法确实可以接受范围数组作为参数。参见:https://hotexamples.com/examples/-/Google_Client/setScopes/php-google_client-setscopes-method-examples.html

您的示例代码表明您确实尝试传入一个数组,但您包装了 Google_Service_Calendar::CALENDARGoogle_Service_Drive::DRIVE 在单引号中,这会将它们变成字符串而不是对它们所代表的值的引用。