Goodle幻灯片:将现有演示文稿的所有幻灯片复制到新的幻灯片中

时间:2018-08-09 13:38:25

标签: java google-slides-api

这可能不是错误,但是可以解决。

以下代码读取演示文稿,并将对象写回为新的演示文稿。问题在于新的演示文稿是空白的!关于为什么会这样的任何想法?

import com.google.api.services.slides.v1.Slides;
import com.google.api.services.slides.v1.model.Page;
import com.google.api.services.slides.v1.model.Presentation;

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;

public class TestReadWrite extends AbstractGoogleDoc {
  public static void main(String... args) throws IOException, GeneralSecurityException {
    try {
      String title = TestReadWrite.class.getSimpleName();

      // Build a new authorized API client service.
      Slides service = createSlideService(title);

      String presentationId = "1zegq0OWG68l1jgo8qsKsWmL47BBSd3_BXJY53ueEdbg";
      Presentation response = service.presentations().get(presentationId).execute();
      List<Page> pages = response.getSlides();
      System.out.printf("The presentation contains %s slides:\n", pages.size());
      for (int i = 0; i < pages.size(); ++i) {
        System.out.printf("- Slide #%s contains %s elements.\n", i + 1, pages.get(i).getPageElements().size());
      }

      response.setPresentationId(null);
      service.presentations().create(response).setFields("presentationId").execute();

    }
    catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
}

这是输出:

The presentation contains 1 slides:
- Slide #1 contains 3 elements.

0 个答案:

没有答案