【问题标题】:Get "Not authorized to access the application ID" after using Google Apps Marketplace API使用 Google Apps Marketplace API 后出现“未授权访问应用程序 ID”
【发布时间】: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


【解决方案1】:

好的,我已经解决了。您必须将所有范围添加到您的应用使用的服务帐户对象(不仅仅是您真正希望服务帐户使用的范围):

$cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/admin.directory.user.readonly', 'https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/appsmarketplace.license'), $private_key);

【讨论】:

  • 我可以确认这确实不需要 - 您只需要范围 https://www.googleapis.com/auth/appsmarketplace.license。根据这个answer,实际上对我有用的是在开发人员控制台中,还添加了 Marketplace API,而不仅仅是 Marketplace SDK
猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 2013-07-31
  • 1970-01-01
  • 2017-12-03
  • 1970-01-01
  • 2015-01-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多