2014-09-30 68 views
0

我很沮丧于此。我有一个PHP脚本示例,使用最新版本的Google API PHP客户端。该脚本功能完美:(403)报告范围内权限不足范围

<?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); 
 
?>

然而,做同样的事情,但对于报告API让我在这个帖子的主题的错误。

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

 
$service = new Google_Service_Reports($client); 
 
$rep = $service->userUsageReport->get("[email protected]", "2014-09-03"); 
 
\t print_r($rep);

我到处找我能想到的找到我需要的权限方面授予。根据prerequisites。我没有在API列表中提供“报告API”,但启用了Admin SDK。

有没有人知道它还能是什么?它在API浏览器和oauth 2游乐场中工作正常。

回答

3

在文档中这不是很清楚,但报告API实际上是Admin SDK的一部分。因此,通过启用Admin SDK,您实际上启用了Reports Api和Admin Apis。

如果您转到admin SDK documentation并单击“创建报告和审核”,您可以看到它直接将您链接到Reports API。

希望这有助于!

+0

不错的想法,但Admin SDK肯定为这个项目启用。 – 2014-10-02 15:59:16