0

I'm stumped on this one. I have an example php script, using the most recent version of the Google API PHP client. This script functions perfectly:

<?php

require_once 'Google/Client.php';
require_once 'Google/Service/Drive.php';

$apiConfig['use_objects'] = true;

$client = new Google_Client();
$client->setClientId('xxx.googleusercontent.com');
$client->setClientSecret('xxx');
$client->setRedirectUri('xxx');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$oldToken = file_get_contents("token.json");
$client->setAccessToken($oldToken);

$service = new Google_Service_Drive($client);
$perms = $service->permissions->listPermissions("example_file_id_here");
print_r($perms);
?>

However, doing the exact same thing but for the reports API gives me the error in the subject of this post.

$client->setScopes(array('https://www.googleapis.com/auth/admin.reports.usage.readonly'));

$service = new Google_Service_Reports($client);
$rep = $service->userUsageReport->get("test@test.com", "2014-09-03");
 print_r($rep);

I've looked everywhere I can think of to find what I need to grant in terms of permissions. According to the prerequisites. I don't have a 'Reports API' available in the list of APIs, but the Admin SDK if enabled.

Does anyone know what else it could be? It works fine in the API explorer and oauth 2 playground.

1 Answers1

3

It is not very clear in the documentation, but reports API is actually part of the Admin SDK. So by enabling Admin SDK, you actually enable both Reports Api and Admin Apis.

If you go to the admin SDK documentation and click under "Create Reports and Audits", you can see that it directly link you to the Reports API.

Hope this helps!

Emily
  • 1,464
  • 1
  • 9
  • 12