Reputation: 3
I am working on my first Google App Script (Script as Webapp) and trying to access a fusion table, but each time I try to access the fusion table I get back insufficient privileges. I am logged in as the owner of the app, so I am not sure why this is happening.
function getReports(){
var authToken = ScriptApp.getOAuthToken();
Logger.log(authToken);
var query = encodeURIComponent("Select * from " + tableId);
queryFusionTables(authToken, query);
}
function queryFusionTables(authToken, query) {
var URL = "https://www.googleapis.com/fusiontables/v1/query?sql="+query+"&key={myKey}";
Logger.log(query);
//Logger.log(authToken);
var response = UrlFetchApp.fetch(URL, {
method: "post",
headers: {
"Authorization": "Bearer " + authToken,
"X-JavaScript-User-Agent": "Google APIs Explorer",
},
});
Logger.log(response.getContentText());
return response.getContentText();
}
Does Anyone have any ideas as to why this is happening?
Upvotes: 0
Views: 162
Reputation: 12673
The OAuth token returned by ScriptApp.getOAuthToken()
is only authorized for the scopes required by your script, which is determined by the Apps Script services you use. For instance, if you were to use DriveApp
the Google Drive API scope would be requested.
The Apps Script code doesn't know you are attempting to use the Fusion Tables API, so it didn't request that scope. However, you are in luck! Apps Script has a built-in integration with Fusion Tables, using the Fusion Tables advanced service. Simply enable the service and Apps Script will take care of the authorization for you, plus provide you with auto-complete.
Upvotes: 1