DocumentList API和GAS。如何与他们结婚? [英] DocumentList API and GAS. How to marry them?
问题描述
如何使用此API?
developers.google.com/google-apps/documents-list
它似乎能够访问修订历史记录Feed。
但是这些例子都在.NET中。如何在Google Apps脚本中应用/使用此API?任何人都知道如何,可以点亮一些东西?也许一个简短的示例代码?
谢谢。
DocLists API。您可以使用此协议与URLFetch和Google oAuth
这是一个快速示例,它以json格式返回修订历史记录
//获取修订历史记录
// resource_id是doc的标识
函数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
//由getRevisionHistory使用
函数googleOAuth_(name,scope){
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl(https://www.google.com/accounts/OAuthGetRequestToken?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};
}
要在DocsList API中发挥更多作用,您可以在Google上看到更多示例Site
https://sites.google.com/site/appsscripttutorial/ urlfetch-and-oauth
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.
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
这篇关于DocumentList API和GAS。如何与他们结婚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!