为我的 Google Docs 插件获取域安装

Getting domain installs for my Google Docs Add-on

我们有一个 Google-docs 插件(基于 Google Apps 脚本构建),为此我们启用了 Google Apps Marketplace SDK - 这样 Google应用程序管理员可以在域级别安装我们的附加组件。

我们注意到一些域现在已经安装了我们的附加组件 - 但我似乎无法找到一种方法来获取有关哪些域安装了我们的信息。有可能吗?

我已经尝试了 Marketplace 许可证 API https://developers.google.com/apps-marketplace/v2/reference/ 但它失败并出现 403 错误 - 未授权访问应用程序 ID

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

我什至尝试创建一个 服务帐户 并使用该服务帐户访问 API 但遇到了同样的错误。

任何输入都会很棒。

到目前为止,这是我的 Java(Groovy 技术上的)代码(响应是我在上面粘贴的 json):

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.http.GenericUrl
import com.google.api.client.http.HttpRequest
import com.google.api.client.http.HttpRequestFactory
import com.google.api.client.http.HttpTransport
import com.google.api.client.json.JsonFactory
import com.google.api.client.json.jackson2.JacksonFactory
import org.springframework.security.access.annotation.Secured

class DataController {

    /**
     * Be sure to specify the name of your application. If the application name is {@code null} or
     * blank, the application will log a warning. Suggested format is "MyCompany-ProductName/1.0".
     */
    private static final String APPLICATION_NAME = "My app name";

    private static final String APPLICATION_ID = "12 digit project number";

    /** E-mail address of the service account. */
    private static final String SERVICE_ACCOUNT_EMAIL = "12digitproejectnumber-compute@developer.gserviceaccount.com";

    /** Global instance of the HTTP transport. */
    private static HttpTransport httpTransport;

    /** Global instance of the JSON factory. */
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();




    def getLicensedInfo() {

        try {
            try {
                httpTransport = GoogleNetHttpTransport.newTrustedTransport();



                GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
                        .setJsonFactory(JSON_FACTORY)
                        .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
                        .setServiceAccountScopes(Collections.singleton("https://www.googleapis.com/auth/appsmarketplace.license"))
                        .setServiceAccountPrivateKeyFromP12File(new File("a/valid/path/to/key.p12"))
                        .build();


                credential.refreshToken();
                String token = credential.getAccessToken();

                HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);


                GenericUrl url = new GenericUrl("https://www.googleapis.com/appsmarket/v2/licenseNotification/"+APPLICATION_ID);

                HttpRequest request = requestFactory.buildGetRequest(url);

                com.google.api.client.http.HttpResponse response = request.execute();

                log.debug(response.parseAsString());


                return;
            } catch (IOException e) {
                System.err.println(e.getMessage());
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }

    }



}

在向 GAM 许可证提出请求时 API 您需要使用您用于列表的相同 Google Developers Console 项目。对于附加组件,这是与脚本关联的控制台项目。