DocumentList API和GAS.如何嫁给他们?

sab*_*nsm 1 google-docs-api google-apps-script google-spreadsheet-api

使用这个API怎么样?

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

它似乎能够访问修订历史记录Feed.

但这些例子都在.NET中.如何在Google Apps脚本中应用/使用此API?任何人都知道如何并且可以解决一些问题 也许一个简短的示例代码?

谢谢.

Waq*_*mad 7

您需要查看DocLists API的协议.您可以使用此协议以及URLFetch和Google oAuth这是一个快速示例,它以json格式返回修订历史记录

//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"};
}
Run Code Online (Sandbox Code Playgroud)

要使用DocsList API进行更多操作,您可以在我的Google网站上查看更多示例 https://sites.google.com/site/appsscripttutorial/urlfetch-and-oauth