在 Google Apps Marketplace API 中收到“无权访问应用程序 ID”

问题描述 投票:0回答:2

我正在尝试列出我的应用程序的所有域安装。

为此我:

  • 为该域私下发布了我的应用程序;
  • 为我的项目同时启用
    Google Apps Marketplace API
    Apps Marketplace SDK
  • 已配置
    Apps Marketplace SDK
    (添加范围:
    "https://www.googleapis.com/auth/appsmarketplace.license"
    );
  • 创建了具有以下角色的服务帐户:项目所有者、项目编辑者;
  • 尝试使用范围正确的凭据从 Java 访问 API,但失败。

我总是遇到同样的 403 错误:

{
    "error": {
         "errors":[{
             "domain": "global",
             "reason": "forbidden",
             "message": "Not authorized to access the application ID"
         }],
         "code":403,"message":"Not authorized to access the application ID"
    }
}

有人可以解释一下我在这里想念什么吗?

google-api-java-client google-apps-marketplace google-workspace
2个回答
0
投票

我添加了更多角色:项目浏览器和项目查看器。他们中的任何一个或他们都似乎已经解决了问题。


0
投票

对我有用的是使用具有

Basic Editor
角色的服务帐户。任何其他特权较低的角色都不起作用,因此它至少必须是编辑者或所有者。然后,我必须关注@A。 R. Younce 回答类似问题

在服务帐号的“详细信息”选项卡上,展开“高级设置”部分,然后点击“创建与 Google Workspace Marketplace 兼容的 OAuth 客户端”按钮。

它并没有立即起作用。我不得不等待 20 分钟才能传播此更改。

这是要测试的示例 Python 脚本:

import os
from google.oauth2 import service_account
from googleapiclient.discovery import build

# Set the path to your service account key file
KEY_FILE_PATH = 'path/to/service-account.json'

# Set the scopes required for the API
SCOPES = ['https://www.googleapis.com/auth/appsmarketplace.license']

def create_service():
    credentials = service_account.Credentials.from_service_account_file(KEY_FILE_PATH, scopes=SCOPES)
    service = build('appsmarket', 'v2', credentials=credentials, static_discovery=False)
    return service

def list_license_notifications():
    service = create_service()

    # Set your application ID
    application_id = '<application-id>'

    # Set the maximum number of results to retrieve (optional)
    max_results = 100

    # Make the API request
    response = service.licenseNotification().list(
        applicationId=application_id, max_results=max_results
    ).execute()

    # Print the license notifications
    notifications = response.get('notifications', [])
    if notifications:
        for notification in notifications:
            print(notification)
    else:
        print('No license notifications found.')

if __name__ == '__main__':
    list_license_notifications()

应用程序 ID 可在 Google Workspace Marketplace SDK 页面的 应用配置 选项卡

找到
© www.soinside.com 2019 - 2024. All rights reserved.