繁体   English   中英

为我的Google文档插件获取域安装

[英]Getting domain installs for my Google Docs Add-on

我们有一个Google-docs加载项(基于Google Apps脚本构建),为此我们启用了Google Apps Marketplace SDK-以便Google Apps管理员可以在域级别安装我们的加载项。

我们注意到,现在已经有几个域安装了我们的附件-但是我似乎找不到找到有关哪些域已安装我们的信息的方法。 可能吗?

我已经尝试了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项目。 对于加载项,这是与脚本关联的控制台项目。

暂无
暂无

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

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