【发布时间】:2016-01-25 16:28:55
【问题描述】:
我有一个网络应用程序并试图找出谷歌域中的哪些用户安装了我的应用程序。我尝试使用这里的代码:Determine if a google user's domain has my marketplace app installed,但它不起作用。我仍然收到错误“(403)未授权访问应用程序ID”作为响应。
代码:
$private_key = file_get_contents('path_to_p.12_key');
$service_account_name = '{service_acc_name}'; // name from developers console
$cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/appsmarketplace.license'), $private_key);
$client = new Google_Client();
$client->setAssertionCredentials($cred);
$url = "https://www.googleapis.com/appsmarket/v2/licenseNotification/{appID}";
$httpRequest = new Google_Http_Request($url, 'GET');
$httpRequest->setBaseComponent($client->getBasePath());
$httpRequest = $client->getAuth()->sign($httpRequest);
try
{
$result = $client->execute($httpRequest);
}
catch (Exception $e)
{
echo $e->getMessage();
}
我还在开发者控制台的项目设置中添加了https://www.googleapis.com/auth/appsmarketplace.license 范围。
我不明白出了什么问题。
【问题讨论】:
-
您是否授予应用市场中的服务帐户访问数据的权限?
-
您是指开发者控制台中的权限吗?在控制台中,该服务帐户具有“可以编辑”权限
-
服务帐户有权访问您未授予其访问权限的任何内容。如果您尝试从 Apps Marketplace 中读取内容,则需要在 spps 市场中授予它权限。百万美元的问题是您能否授予其他用户查看您数据的权限
-
从此处完成“将域范围的权限委派给服务帐户”块中的步骤:developers.google.com/identity/protocols/OAuth2ServiceAccount 我还在我的测试域的管理控制台中授予了服务帐户的权限。就这样。也许我误解了你在谈论什么样的权限,但我没有看到其他任何东西。
-
范围定义了您的应用程序需要的权限。您应该只请求您需要的范围。通常你只请求你需要的范围,但在服务帐户的情况下,请求完全访问是安全的。
标签: php google-api-php-client google-apps-marketplace