如何从Java servlet运行部署为Web应用程序的Google Apps脚本?

时间:2014-09-19 16:13:19

标签: java servlets google-apps-script google-apps

我创建了一个GAS并将其部署为google web app。 它随https://script.google.com/macros/s/..../exec网址提供。 现在我想从Java servlet运行它。 我在console.developers.google.com中创建了应用程序,为服务帐户 API KEY 创建了 CLIENT ID ,并且私钥文件< /强>

现在我尝试按如下方式运行脚本:

    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    // Build service account credential.
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
        .setJsonFactory(jsonFactory)
        .setServiceAccountId("...@developer.gserviceaccount.com")
        .setServiceAccountScopes(Collections.singleton("https://script.google.com"))
        .setServiceAccountPrivateKeyFromP12File(new File(getClass().getClassLoader().getResource("key/eForms-055a7029cd36.p12").toURI()).getAbsoluteFile())
        .build();

            // Set up and execute a Google Cloud Storage request.
    String URI = "https://script.google.com/macros/s/.../exec?payload="+form.toString();
    HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
    GenericUrl url = new GenericUrl(URI);
    HttpRequest http_request = requestFactory.buildGetRequest(url);
    HttpResponse response = http_request.execute();
    String content = response.parseAsString();

我得到了

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "invalid_grant"
}

我认为我设置了错误的插槽,但设置了哪一个?

0 个答案:

没有答案