简体   繁体   English

使用Python客户端验证GSuite Marketplace应用的GSuite(Google Apps)域的许可证

[英]Using Python client to verify license of GSuite (Google Apps) domain for a GSuite Marketplace App

I created a service account, instead of using the default one, under my google cloud project and I enabled dwd. 我在Google云端项目下创建了一个服务帐户,而不使用默认帐户,并且启用了dwd。

I then enabled Google Apps Marketplace API from the google cloud console. 然后,我从Google云控制台启用了Google Apps Marketplace API

Then I published a marketplace app as available only to users of my GSuite domain with api_console_project_id in manifest.json set to my project's id. 然后,我发布了一个市场应用程序,仅对我的GSuite域的用户可用,并且manifest.json中的api_console_project_id设置为项目的ID。

The status in the developer dashboard is 开发人员信息中心中的status

Published
GAM: Pending

I then had my domain admin install the app. 然后,我让我的域管理员安装了该应用程序。

I believe I am now all set to use the appsmarket v2 Python client to verify license of my domain for the app now. 我相信我现在都准备使用appsmarket v2 Python客户端来验证我的应用域的许可证。

Below is how I am doing it 以下是我的做法

from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build


path_to_key = 'path/to/my/service_account_key.json'
scopes = ['https://www.googleapis.com/auth/appsmarketplace.license']
APPLICATION_ID = 'xxxxxxxxxxxx'
domain = 'xxxxxx.com'

credentials = ServiceAccountCredentials.from_json_keyfile_name(
            path_to_key, scopes)
authorized_http = credentials.authorize(Http())
appsmarket_api_client = build(
     'appsmarket', 'v2',   http=authorized_http)
appsmarket_license_info = appsmarket_api_client.customerLicense().get(
            applicationId=APPLICATION_ID, customerId=domain).execute()
domain_is_licensed = (appsmarket_license_info['state'] == 'ACTIVE')

But my code breaks at 但是我的代码在

appsmarket_license_info = appsmarket_api_client.customerLicense().get(
    applicationId=APPLICATION_ID, customerId=domain).execute()

with HttpError 403 when requesting https://www.googleapis.com/appsmarket/v2/customerLicense/xxxxxxxxxxxx/xxxxxx.com?alt=json returned "Not authorized to access the application ID HttpError 403 when requesting https://www.googleapis.com/appsmarket/v2/customerLicense/xxxxxxxxxxxx/xxxxxx.com?alt=json returned "Not authorized to access the application ID出现HttpError 403 when requesting https://www.googleapis.com/appsmarket/v2/customerLicense/xxxxxxxxxxxx/xxxxxx.com?alt=json returned "Not authorized to access the application ID

I am unable to debug why this is happening. 我无法调试为什么会这样。

What I missed was that I didn't add the service account as a member of the project and give it edit access to the project. 我错过的是我没有将服务帐户添加为项目成员,并没有授予该项目编辑权限。 Now it's working. 现在可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM