Embedding Google drive videos on a Google Site usi

2019-08-28 23:23发布

I'm looking for a programmatic way to include videos from Google Drive on a Google Site. My current plan is to have a spreadsheet seeded with the embed URL per row that is then mined via Google Apps Script to embed the content.

However, at the core of this program, I believe I am running into a known issue based on the similarity to http://code.google.com/p/google-apps-script-issues/issues/detail?id=1649 which was a Google bug with embedding a YouTube video on a Google Site.

As shown at this URL below, I have very small HTML file that plays Apple's example MP4 file which I uploaded to a Google Drive so I can embed it and which works as expected:

http://www.pccc.com/downloads/junk/test/test.html

However, if I duplicate the same HTML for an Apps Script, all I see is the grey border and the "this is a test" text that was added to confirm the latest revision was published:

function doGet(e) {
  var html = '<iframe src="https://docs.google.com/a/documentshare.com/file/d/0B7wNkTj2wH_TLTdwcWo2NW5SWnM/preview" width="640" height="385"></iframe> This is a test';
  return HtmlService.createHtmlOutput(html);
}

Any pointers appreciated.

2条回答
贼婆χ
2楼-- · 2019-08-29 00:17

Unfortunately the HtmlService doesn't support iframes.

查看更多
Bombasti
3楼-- · 2019-08-29 00:19

This is doable but in a different way. You can have full access to a sites page HTML including iframes via script. See the doumentation. Do the edit first manually on the sites page: Insert > Video > Google docs. Then use the HTML generated as a template to write your own programmatically.

Edit: For example, follow these steps:

  1. Create a web page called TEST
  2. Edit the page and write "this is a test" and then Insert > Video > Google Docs Video (the url to paste is: https://docs.google.com/a/documentshare.com/file/d/0B7wNkTj2wH_TLTdwcWo2NW5SWnM/preview
  3. Save the page and run this code (authorise when prompted and rerun).
  4. Refresh your page in the browser.

The code will change the page programatically but you will still have a working video.

function myFunction() {
      //Change the domain and site to yours below
      var page = SitesApp.getSite('YOURDOMAIN', 'YOURSITE').getChildByName('TEST');
      var html = page.getHtmlContent();
      Logger.log(html);
      page.setHtmlContent(html.replace("test", "test at " + new Date()));
      var newhtml = page.getHtmlContent();
      Logger.log(newhtml);
      return;
    }
查看更多
登录 后发表回答