小编Raf*_*iak的帖子

使用谷歌Java客户端复制电子表格后,自定义谷歌应用程序脚本无效

我有谷歌电子表格模板与我试图复制的自定义插件

def copyTemplateSpreadsheet(Drive driveService) {
    File templateCopy = new File()
    templateCopy.setName("excel-template")

    def copiedFile = driveService.files().copy(templateSpreadsheetId, templateCopy).execute()
    setCorrectPermission(driveService, copiedFile.getId())
    copiedFile
}

private void setCorrectPermission(Drive driveService, def fileId) {
    Permission newPermission = new Permission();
    newPermission.setType("anyone");
    newPermission.setRole("writer");
    driveService.permissions().create(fileId, newPermission).execute();
}
Run Code Online (Sandbox Code Playgroud)

问题是复制的电子表格已打破附加组件(未在附加组件菜单中显示).脚本编辑器中有正确的附加代码,但是当我尝试运行任何函数时,我收到错误消息

"We're sorry, a server error occurred. Please wait a bit and try again"
Run Code Online (Sandbox Code Playgroud)

请记住,完全相同的代码在我的模板电子表格中运行良好.即使我删除所有代码并留空onOpen函数,仍会出现错误.

当我使用常规google驱动器网站(drive.google.com)执行此操作时,复制加载项效果很好,并且当我尝试使用google的API Explorer时也能正常工作(https://developers.google.com/drive/v3/reference/ files/copy#try-it).问题似乎只有在使用sdk时(至少是java一个 - 我没有尝试过任何其他的)

另请注意,我正在使用按照本文所述创建的Google服务帐户https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount

并使用以下代码创建Drive实例

 Drive getDriveService() throws GeneralSecurityException, IOException, URISyntaxException {
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();
    GoogleCredential …
Run Code Online (Sandbox Code Playgroud)

google-apps-script google-drive-api google-oauth

5
推荐指数
1
解决办法
751
查看次数

线程不能用作线程

我对线程有一些奇怪的问题(或者至少对我来说很奇怪).我有这样的主要

public class Main {
public static void main(String[] args) {
    int port = 5555;
    String server = "127.0.0.1";
    int x=20, y=20, squareSize = 25;


    Thread connectionManager = new ConnectionManager(server, port, x, y);
    connectionManager.run();
    System.out.print("BUM");
Run Code Online (Sandbox Code Playgroud)

ConnectionManager的位置

public class ConnectionManager extends Thread{
private String server;
private int port;
private int x;
private int y; //dlugosc mapy

private Socket socket;
private int[][] currentMap;
File file;
PrintWriter printWriter;

public ConnectionManager(String server, int port, int x, int y) {
    this.server = server;
    this.port = …
Run Code Online (Sandbox Code Playgroud)

java multithreading

-2
推荐指数
1
解决办法
51
查看次数