为我的Google文档插件获取域名安装 [英] Getting domain installs for my Google Docs Add-on

查看:179
本文介绍了为我的Google文档插件获取域名安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Google文档附加组件(基于Google Apps脚本),我们启用了Google Apps Marketplace SDK,以便Google Apps管理员可以在域级别安装我们的附件。

b
$ b

我们注意到有几个域现在已经安装了我们的插件 - 但我似乎无法找到获取关于哪些域已安装我们的信息的方法。甚至有可能吗?



我已经试过Marketplace许可证API https://developers.google.com/apps-marketplace/v2/reference/ ,但会失败,并显示403错误 - 未被授权访问应用程序ID

  {
错误:{
错误:[
{
domain:global,
reason:禁止,
消息:无权访问应用程序ID
}
],
code:403,
message:无权访问应用程序ID
}
}
pre>

我甚至尝试创建服务帐户,并使用服务帐户访问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.goog le.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 {
$ b $ / **
*请务必指定您的应用程序的名称。如果应用程序名称为{@code null}或
* blank,则应用程序将记录警告。建议的格式是MyCompany-ProductName / 1.0。
* /
private static final String APPLICATION_NAME =我的应用名称;

private static final String APPLICATION_ID =12位数的项目编号;

/ **服务帐户的电子邮件地址。 * /
private static final String SERVICE_ACCOUNT_EMAIL =12digitproejectnumber-compute@developer.gserviceaccount.com;

/ ** HTTP传输的全局实例。 * /
私人静态HttpTransport httpTransport;

/ ** JSON工厂的全局实例。 * /
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();



$ b def getLicensedInfo(){

尝试{
尝试{
httpTransport = GoogleNetHttpTransport.newTrustedTransport ();


$ b GoogleCredential凭证=新的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项目。在加载项的情况下,这是与脚本相关的控制台项目。


We have a Google-docs Add-on (built on Google Apps Script) for which we enabled the Google Apps Marketplace SDK - so that Google Apps Administrators could install our add-on at the domain level.

We have noticed a few domains have now installed our add-on - but I can't seem to find a way to get information on which domains have installed us. Is it even possible?

I have tried the Marketplace license API https://developers.google.com/apps-marketplace/v2/reference/ but it fails with a 403 error - Not authorized to access the application 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"
 }
}

I even tried by creating a service account and accessed the API using the service account but got the same error.

Any input would be awesome.

Here's my Java (Groovy technically) code so far (the response is the json I've pasted above):

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();
        }

    }



}

解决方案

When making the request to the GAM License API you need to use the same Google Developers Console project that you used for your listing. In the case of an add-on, this is the console project associated with the script.

这篇关于为我的Google文档插件获取域名安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆