php - 无法使用 PHP 在 google apis 请求中添加多个范围
问题描述
我正在研究 google api 并访问 google 驱动器日历等,同时请求单个范围,即 google 表格或文档,它工作正常,但无法在单个请求中设置多个范围。
我尝试了其他论坛上讨论的各种事情,例如添加多个,例如使用逗号分隔添加多个范围
$client->setScopes(Google_Service_Calendar::CALENDAR,Google_Service_Drive::DRIVE);
还创建了新数组,例如
$scopes=['Google_Service_Calendar::CALENDAR','Google_Service_Drive::DRIVE']
但没有一个对我有用
这是我的代码
$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::CALENDAR和Google_Service_Drive::DRIVE包裹在单引号中,这会将它们转换为字符串,而不是对它们所代表的值的引用。
推荐阅读
- c99 - 为什么我得到分段错误(核心转储)
- python - 如何正确地将 excel 表中的数据分配给 python/pyomo(具体模型)上的参数
- python - 如何找到从特定字符位置开始的单词而不是字符串中的单词位置?
- excel - 读取 Excel 数据的 VM Domino 服务器在 RDP 会话处于活动状态时工作
- python - 使用 plotly 在一个图中绘制多条 3d 线
- protocol-buffers - 对 pbtools 中的重复条目进行编码
- python - ldap python result3 函数结果中缺少 LDAP 属性,但出现在 ldapsearch 命令结果中
- oracle - 尝试执行查询时忽略 $
- spring-boot - 基于微服务的环境中的 Keycloak 身份验证流程
- php - 为什么身份验证登录视图不会扩展基本布局