我正在使用 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 调用。