DocumentList API and GAS. How to marry them?

2019-06-01 23:40发布

How about using this API?

developers.google.com/google-apps/documents-list

It seems to be able to access the revision history feed.

But the examples are in .NET. How do I apply/use this API in Google Apps Script? Anyone knows how and can shed some light? Maybe a short sample code?

Thanks.

2条回答
可以哭但决不认输i
2楼-- · 2019-06-02 00:25

You need to look on the protocol for DocLists API. You can use this protocol alongwith URLFetch and Google oAuth Here is a quick example, which returns the revision history in json format

//Get revison history
//resource_id is the id of the doc
function getRevisionHistory(resource_id){
  var scope = 'https://docs.google.com/feeds/';
  var fetchArgs = googleOAuth_('docs', scope);
  fetchArgs.method = 'GET';
  var url = scope + 'default/private/full/'+resource_id+'/revisions?v=3&alt=json';
  var urlFetch = UrlFetchApp.fetch(url, fetchArgs);
  var jsonFeed = Utilities.jsonParse(urlFetch.getContentText()).feed.entry;
  return jsonFeed
}

//Google oAuth
//Used by getRevisionHistory
function googleOAuth_(name,scope) {
  var oAuthConfig = UrlFetchApp.addOAuthService(name);
  oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oAuthConfig.setConsumerKey("anonymous");
  oAuthConfig.setConsumerSecret("anonymous");
  return {oAuthServiceName:name, oAuthUseToken:"always"};
}

To play more with DocsList API, you can see some more example on my Google Site https://sites.google.com/site/appsscripttutorial/urlfetch-and-oauth

查看更多
该账号已被封号
3楼-- · 2019-06-02 00:25

Check out: https://sites.google.com/site/scriptsexamples/custom-methods/driveservice Just copy the source into your file.

I will be adding the missing methods in the next few weeks. Revisions are certainly on my list.

You will be able to use these libraries like: DOCS_LIST_API.GdocToFormat (docID, format)

No need to setup OAuth, it will be built in.

查看更多
登录 后发表回答