从Drive.Files.list获取新的Google网站发布的URL [英] Getting New Google Site Published URL from Drive.Files.list

查看:75
本文介绍了从Drive.Files.list获取新的Google网站发布的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在努力列出我们域内的所有网站. 我可以使用Drive.File.list来获得,这很好.我可以查询并获取站点名称和所有者电子邮件,但是,我找不到找到站点发布URL的方法.

So I'm working on something to list all sites within our domain. I can get this using Drive.File.list, and that's fine. I can query and get the name of the site and the owners email, however, I can't figure a way to get the sites published URL.

这是我到目前为止所拥有的核心:

This is the core of what I have so far:

function getNewSites() {
  var responses = Drive.File.list({
    corpus: "DEFAULT",
    maxResults: 1,
    q: 'mimeType="application/vnd.google-apps.site" and title="Test Site"',
    fields: "items/owners/emailAddress,items/title"
  });
  Logger.log(responses);
}

哪个返回:

{
 "items": [
  {
   "title": "Test Site",
   "owners": [
    {
     "emailAddress": "email@address.co.uk"
    }
   ]
  }
 ]
}

您可以获取编辑URL和嵌入链接等,但是我根本不知道如何获取已发布的U​​RL(不是该URL中使用的文件名) 该示例中的URL是https://sites.google.com/domain.co.uk/testsaaaaa/home

You can get edit URLs and embed links etc, but I can't figure out how to get the published URL at all (Is it's not the file name that is used in that URL) The URL in that example is https://sites.google.com/domain.co.uk/testsaaaaa/home

在有效负载中看不到的任何地方都没有引用'testsaaaaa'.

'testsaaaaa' isn't referenced anywhere that I can see in the payload.

推荐答案

我不确定可以使用Drive API来完成此操作,因为Drive API或多或少与通用文件属性有关,而与文档无关.我使用Google APIs Explorer检查了v2和v3,但无法获取任何形式的已发布"信息.

I'm not sure this can be done with the Drive API, since the Drive API is more or less about generic file properties and not document-specific things. I checked both v2 and v3 using the Google APIs Explorer, and was unable to obtain any sort of "published" information.

Drive v2演示链接

驱动器v3演示链接

很遗憾,Google Sites API与新" Google Sites不兼容(尚未?).使用旧站点,您可以使用网址访问此发布的URL映射请求: https://developers.google.com/sites/docs/1.0 /developers_guide_protocol#WebAddressMappings

Unfortunately, the Google Sites API is not (yet?) compatible with the "new" Google Sites. With old sites, you could access this published URL with a web address mapping request: https://developers.google.com/sites/docs/1.0/developers_guide_protocol#WebAddressMappings

您可以通过编辑Apps脚本清单文件以包含范围"https://sites.google.com/feeds"

You can authorize the Google Sites API by editing your Apps Script manifest file to include the scope "https://sites.google.com/feeds"

这是一个示例脚本(同样,该脚本仅适用于经典" Google站点:

This is an example script (that again, will only work for "classic" Google Sites:

function ClassicSitesLister() {
  // https://developers.google.com/sites/docs/1.0/reference#feed_ListSites
  const url = 'https://sites.google.com/feeds/site/site?with-mappings=true'; // replace final 'site' with custom domain
  const options = {
    Authorization: "Bearer " + ScriptApp.getOAuthToken()
  };
  const resp = UrlFetchApp.fetch(url, {headers: options});
  const content = resp.getContentText(); // gets XML content
  console.log({message: "Classic Sites data", xmlContent: content});
}

记录的数据与此类似:

<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' 
     xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005' xmlns:gs='http://schemas.google.com/spreadsheets/2006' 
     xmlns:thr='http://purl.org/syndication/thread/1.0' xmlns:sites='http://schemas.google.com/sites/2008' 
     xmlns:dc='http://purl.org/dc/terms' xmlns:gAcl='http://schemas.google.com/acl/2007'>
  <id>https://sites.google.com/feeds/site/site</id>
  <updated>2018-10-08T16:09:52.181Z</updated>
  <title>Site</title>
  <link rel='alternate' type='text/html' href='https://sites.google.com/feeds/site/site'/>
  <link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://sites.google.com/feeds/site/site'/>
  <link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='https://sites.google.com/feeds/site/site'/>
  <link rel='self' type='application/atom+xml' href='https://sites.google.com/feeds/site/site?with-mappings=true'/>
  <generator version='1' uri='http://sites.google.com'>Google Sites</generator>
  <openSearch:startIndex>1</openSearch:startIndex>
  <entry gd:etag='&quot;KXsmYD5aEw..&quot;'>
    <id>https://sites.google.com/feeds/site/site/......</id>
    <updated>2015-08-25T20:44:44.336Z</updated>
    <app:edited xmlns:app='http://www.w3.org/2007/app'>2015-08-25T20:44:44.336Z</app:edited>
    <title>......</title>
    <summary>......</summary>
    <link rel='alternate' type='text/html' href='https://sites.google.com/site/....../'/>
    <link rel='http://schemas.google.com/acl/2007#accessControlList' type='application/atom+xml' href='https://sites.google.com/feeds/acl/site/site/.....'/>
    <link rel='edit' type='application/atom+xml' href='https://sites.google.com/feeds/site/site/.....?with-mappings=true'/>
    <link rel='self' type='application/atom+xml' href='https://sites.google.com/feeds/site/site/......'/>
    <sites:siteName>......</sites:siteName>
    <sites:theme>......</sites:theme>
  </entry>
</feed>

在上面的提要中,<link rel='alternate'>href属性是该特定网站的已发布URL.按照链接的示例,如果您为自定义域添加别名,该自定义域应作为自己的条目显示在<link rel='webAddressMapping' href='....">下,其中可能有多个.

In the above feed, the <link rel='alternate'>'s href attribute is the published URL for that particular site. Per the linked example, if you alias to a custom domain that should appear as its own entry under <link rel='webAddressMapping' href='....">, of which there may be multiple.

这篇关于从Drive.Files.list获取新的Google网站发布的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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