Ok, read more and make it up at last.
What I was missing was that to authenticate licensing endpoints, you need to use a service account , not a regular user account. What makes sense is why the Try Now feature on the documentation pages doesn’t work at all.
Unfortunately, we use PHP, and google-api-php-client do not yet have services for the licensing API. However, the client project shows an example of using a service account instead of the user's normal OAuth2 stream.
I used this example and stole the source code a bit from the Resource.php call
method to call the Client License Endpoint to check if our application is installed in the domain or not:
$privateKey = file_get_contents('path/to/private-key.p12'); $serviceAccountName = ' 12345-j@developer.gserviceaccount.com '; $cred = new \Google_Auth_AssertionCredentials( $serviceAccountName, array('https://www.googleapis.com/auth/appsmarketplace.license'), $privateKey ); $client = new \Google_Client(); $client->setApplicationName('Apps_Marketplace_Licensing_Check'); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $url = \Google_Http_REST::createRequestUri( 'appsmarket/v2/', 'customerLicense/{appId}/{customerId}', [ 'appId' => ['location' => 'path', 'type' => 'string', 'value' => $appId], 'customerId' => ['location' => 'path', 'type' => 'string', 'value' => $domain] ] ); $httpRequest = new \Google_Http_Request($url, 'GET'); $httpRequest->setBaseComponent($client->getBasePath()); $httpRequest = $client->getAuth()->sign($httpRequest); $result = $client->execute($httpRequest); $isDomainInstalled = ($result && isset($result['state']) && $result['state'] == 'ACTIVE');
We hope that the people in the google-api-php-client project will eventually add the true service for these endpoints, but so far this workaround is not too terribly painful.
source share