Created
May 17, 2013 11:02
-
-
Save soundTricker/5598402 to your computer and use it in GitHub Desktop.
Google Apps ScriptからCloud Datastore APIへのクエリ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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