Skip to content

Instantly share code, notes, and snippets.

@soundTricker
Created May 17, 2013 11:02
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save soundTricker/5598402 to your computer and use it in GitHub Desktop.
Save soundTricker/5598402 to your computer and use it in GitHub Desktop.
Google Apps ScriptからCloud Datastore APIへのクエリ
function myFunction() {
var option = googleOAuth_();
option.method = "post";
option.contentType = 'application/json';
option.payload = JSON.stringify({
"query":
{
"kinds":
[
{
"name": "DemoUser"
}
]
}
});
var res = UrlFetchApp.fetch("https://www.googleapis.com/datastore/v1beta1/datasets/"+ScriptProperties.getProperty('DATASETS_ID')+"/runQuery?key=" + ScriptProperties.getProperty('API_KEY') , option);
var json = JSON.parse(res.getContentText());
Logger.log(res.getContentText());
}
function googleOAuth_() {
var oAuthConfig = UrlFetchApp.addOAuthService('datastore');
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/"+
"OAuthGetRequestToken?scope=https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/datastore");
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey('anonymous');
oAuthConfig.setConsumerSecret('anonymous');
return {oAuthServiceName:'datastore', oAuthUseToken:"always"};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment