I am trying to import data (in json format) from an app engine application into a Google spreadsheet.
We need to be authenticated with our Google (apps for business) account to reach the json.
For now, i am just trying to get the contents into a cell. So, following the google documentation ( https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app ), i have tried this simple code:
function getCC() {
// Setup OAuthServiceConfig
var oAuthConfig = UrlFetchApp.addOAuthService('google');
oAuthConfig.setAccessTokenUrl('https://app-id.appspot.com/_ah/OAuthGetAccessToken');
oAuthConfig.setRequestTokenUrl('https://app-id.appspot.com/_ah/OAuthGetRequestToken');
oAuthConfig.setAuthorizationUrl('https://app-id.appspot.com/_ah/OAuthAuthorizeToken');
oAuthConfig.setConsumerKey('app-id.appspot.com');
oAuthConfig.setConsumerSecret('ConsumerSecret');
var options =
{
"oAuthServiceName" : 'google',
"oAuthUseToken" : 'always',
"method": 'GET'
};
var resp = UrlFetchApp.fetch('https://app-id.appspot.com/rest/na/customer/all', options);
// clear everything in the sheet
SpreadsheetApp.getActiveSheet().clearContents().clearFormats();
// set the values in the sheet (as efficiently as we know how)
SpreadsheetApp.getActiveSheet().getRange(1, 1).setValue(resp);
}
I got this error:
Request failed for returned code 302. Truncated server response: (use muteHttpExceptions option to examine full response) (line 19, file "basic")
So i have followed this : https://code.google.com/p/google-apps-script-issues/issues/detail?id=3478 but i have the exact same error message in the logs :/
Do you have any idea how to resolve this?
Thanks
I am trying to import data (in json format) from an app engine application into a Google spreadsheet.
We need to be authenticated with our Google (apps for business) account to reach the json.
For now, i am just trying to get the contents into a cell. So, following the google documentation ( https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app ), i have tried this simple code:
function getCC() {
// Setup OAuthServiceConfig
var oAuthConfig = UrlFetchApp.addOAuthService('google');
oAuthConfig.setAccessTokenUrl('https://app-id.appspot.com/_ah/OAuthGetAccessToken');
oAuthConfig.setRequestTokenUrl('https://app-id.appspot.com/_ah/OAuthGetRequestToken');
oAuthConfig.setAuthorizationUrl('https://app-id.appspot.com/_ah/OAuthAuthorizeToken');
oAuthConfig.setConsumerKey('app-id.appspot.com');
oAuthConfig.setConsumerSecret('ConsumerSecret');
var options =
{
"oAuthServiceName" : 'google',
"oAuthUseToken" : 'always',
"method": 'GET'
};
var resp = UrlFetchApp.fetch('https://app-id.appspot.com/rest/na/customer/all', options);
// clear everything in the sheet
SpreadsheetApp.getActiveSheet().clearContents().clearFormats();
// set the values in the sheet (as efficiently as we know how)
SpreadsheetApp.getActiveSheet().getRange(1, 1).setValue(resp);
}
I got this error:
Request failed for returned code 302. Truncated server response: (use muteHttpExceptions option to examine full response) (line 19, file "basic")
So i have followed this : https://code.google.com/p/google-apps-script-issues/issues/detail?id=3478 but i have the exact same error message in the logs :/
Here with HttpmuteExceptions = true :
function getCC() {
var oAuthConfig = UrlFetchApp.addOAuthService('google');
oAuthConfig.setAccessTokenUrl('https://app-id.appspot.com/_ah/OAuthGetAccessToken');
oAuthConfig.setRequestTokenUrl('https://app-id.appspot.com/_ah/OAuthGetRequestToken');
oAuthConfig.setAuthorizationUrl('https://app-id.appspot.com/_ah/OAuthAuthorizeToken');
oAuthConfig.setConsumerKey('app-id.appspot.com');
oAuthConfig.setConsumerSecret('ConsumerSecret');
var fetchParameters = {};
fetchParameters.oAuthServiceName = 'google';
fetchParameters.oAuthUseToken = 'always';
fetchParameters.method = 'GET';
fetchParameters.muteHttpExceptions = true
try {
var url = 'https://app-id.appspot.com/oauth/na/customer/all';
var result = UrlFetchApp.fetch(url, fetchParameters);
SpreadsheetApp.getActiveSheet().clearContents().clearFormats();
SpreadsheetApp.getActiveSheet().getRange(1, 1).setValue(result);
} catch (e) {
Logger.log(e);
}
}
Logging output:
[14-01-27 11:48:33:692 CET] getResponseCode: function getResponseCode() {/*
*/}
[14-01-27 11:48:33:692 CET] getContentText: function getContentText() {/*
*/}
[14-01-27 11:48:33:692 CET] getContent: function getContent() {/*
*/}
[14-01-27 11:48:33:693 CET] getAs: function getAs() {/*
*/}
[14-01-27 11:48:33:693 CET] getHeaders: function getHeaders() {/*
*/}
[14-01-27 11:48:33:693 CET] toString: function toString() {/*
*/}
[14-01-27 11:48:33:693 CET] getBlob: function getBlob() {/*
*/}
[14-01-27 11:48:33:693 CET] getAllHeaders: function getAllHeaders() {/*
*/}
I am trying to import data (in json format) from an app engine application into a Google spreadsheet.
We need to be authenticated with our Google (apps for business) account to reach the json.
For now, i am just trying to get the contents into a cell. So, following the google documentation ( https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app ), i have tried this simple code:
function getCC() {
// Setup OAuthServiceConfig
var oAuthConfig = UrlFetchApp.addOAuthService('google');
oAuthConfig.setAccessTokenUrl('https://app-id.appspot.com/_ah/OAuthGetAccessToken');
oAuthConfig.setRequestTokenUrl('https://app-id.appspot.com/_ah/OAuthGetRequestToken');
oAuthConfig.setAuthorizationUrl('https://app-id.appspot.com/_ah/OAuthAuthorizeToken');
oAuthConfig.setConsumerKey('app-id.appspot.com');
oAuthConfig.setConsumerSecret('ConsumerSecret');
var options =
{
"oAuthServiceName" : 'google',
"oAuthUseToken" : 'always',
"method": 'GET'
};
var resp = UrlFetchApp.fetch('https://app-id.appspot.com/rest/na/customer/all', options);
// clear everything in the sheet
SpreadsheetApp.getActiveSheet().clearContents().clearFormats();
// set the values in the sheet (as efficiently as we know how)
SpreadsheetApp.getActiveSheet().getRange(1, 1).setValue(resp);
}
I got this error:
Request failed for returned code 302. Truncated server response: (use muteHttpExceptions option to examine full response) (line 19, file "basic")
So i have followed this : https://code.google.com/p/google-apps-script-issues/issues/detail?id=3478 but i have the exact same error message in the logs :/
EDIT
It worked.
I have used the same code and put it in another script file. I think there was a problem with Oauth keeping the old informations.