0

I am using the PHP library to use the Android Management API. I can update policies successfully. But I am unable to create a WebToken needed for the Web App iframe.

I have set a credential file. I do

$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope("https://www.googleapis.com/auth/androidmanagement");
$client->setApplicationName("MyAppName");
$androidmanagementService = new Google_Service_AndroidManagement($client);

Then I try to create a WebToken for the request:

$webTokens = $androidmanagementService->enterprises_webTokens;
$webToken = new Google_Service_AndroidManagement_WebToken();

My understanding is that only the ParentFrameUrl and Permissions are needed, everything else will be set in the answer:

$webToken->setPermissions(array("APPROVE_APPS"));
$webToken->setParentFrameUrl("http://37.71.157.174/mdm/");

But I tried also to set the other values:

//$webToken->setName("MyWebAppView");
//$webToken->setValue("98784");

Then I try to create the WebToken :

$webtoken = $webTokens->create("enterprises/entname", $webToken);

And I always get this Google_Service_Exception:

{ "error": { "code": 400, "message": "Invalid parameter: tokenSpec.parent", "errors": [ { "message": "Invalid parameter: tokenSpec.parent", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }

The full PHP exception is:

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

I have no idea what is wrong. But Everything before the WebToken part work for the other API call.

  • Here is the PHP library : https://github.com/googleapis/google-api-php-client – christophe Apr 29 '19 at 14:32
  • Have you been white-listed by the google to access the EMM API? Also, which solution type are implementing? Work Profile? Device Owner? – N0000B Apr 29 '19 at 16:49
  • Hi N000B, I am using the Android Management API (https://developers.google.com/android/management/introduction) which may not be the API you are referring to. The Android Management API is opened to all for up to 1000 devices. – christophe Apr 30 '19 at 07:33

1 Answers1

0

The URL of the parent frame must use the HTTPS scheme. I think that's the issue you're hitting.

This is mentioned in the documentation of the WebToken resource but it's true that the error message could be clearer.

Fred
  • 2,191
  • 1
  • 12
  • 14
  • Thanks Fred for the help. It works now with https. I read this page many times and failed to see the https requirement. Sorry about that. – christophe May 02 '19 at 11:04