android - 无法使用 google-api-php-client 为 Web App iframe 创建 WebToken
问题描述
我正在使用 PHP 库来使用 Android Management API。我可以成功更新策略。但我无法创建 Web App iframe 所需的 WebToken。
我已经设置了一个凭证文件。我愿意
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope("https://www.googleapis.com/auth/androidmanagement");
$client->setApplicationName("MyAppName");
$androidmanagementService = new Google_Service_AndroidManagement($client);
然后我尝试为请求创建一个 WebToken:
$webTokens = $androidmanagementService->enterprises_webTokens;
$webToken = new Google_Service_AndroidManagement_WebToken();
我的理解是只需要 ParentFrameUrl 和 Permissions,其他一切都将在答案中设置:
$webToken->setPermissions(array("APPROVE_APPS"));
$webToken->setParentFrameUrl("http://37.71.157.174/mdm/");
但我也尝试设置其他值:
//$webToken->setName("MyWebAppView");
//$webToken->setValue("98784");
然后我尝试创建 WebToken :
$webtoken = $webTokens->create("enterprises/entname", $webToken);
我总是得到这个 Google_Service_Exception:
{ "error": { "code": 400, "message": "Invalid parameter: tokenSpec.parent", "errors": [ { "message": "Invalid parameter: tokenSpec.parent", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }
完整的 PHP 例外是:
Uncaught Google_Service_Exception: { "error": { "code": 400, "message": "Invalid parameter: tokenSpec.parent", "errors": [ { "message": "Invalid parameter: tokenSpec.parent", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } } in /var/www/vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #0 /var/www/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 /var/www/vendor/google/apiclient/src/Google/Task/Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /var/www/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run() #3 /var/www/vendor/google/apiclient/src/Google/Client.php(798): Google_Http_REST::execute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_ in /var/www/vendor/google/apiclient/src/Google/Http/REST.php on line 118
我不知道出了什么问题。但是 WebToken 部分之前的所有内容都适用于其他 API 调用。
解决方案
父框架的 URL 必须使用 HTTPS 方案。我认为这就是你要解决的问题。
WebToken 资源的文档中提到了这一点,但确实错误消息可能更清楚。
推荐阅读
- javascript - React Native Expo-Camera 录制视频发现问题用户拒绝需要音频权限
- python - facebook广告api的python字符串字典
- python - 给定 A = S*D*ST (D 是对角矩阵,S/ST 是任意 nxn 矩阵) A 的特征值不应该对应于 D 的对角线条目吗?
- c# - 我怎样才能让我的角色立足于unity3d
- python - 我似乎无法从网络上抓取 href 或文本
- permissions - Microsoft graph api:有些用户在使用我的应用程序时得到 403,而其他用户却没有,为什么?
- reactjs - 如何在调度挂钩 Reactjs 中发送回调
- swiftui - SwiftUI 自定义选项卡栏导航:图标选项卡时返回根视图
- excel - 将带有标签的多行文本也从 Word 插入到一个 Excel 单元格中
- php - Laravel Eloquent withCount() 不应用额外的约束