Import JSON from app engine to google spreadsheet

2 views
Skip to first unread message

zakiz via StackOverflow

unread,
Jan 23, 2014, 10:20:32 AM1/23/14
to google-appengin...@googlegroups.com

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



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/21312172/import-json-from-app-engine-to-google-spreadsheet

zakiz via StackOverflow

unread,
Jan 27, 2014, 6:12:47 AM1/27/14
to google-appengin...@googlegroups.com

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() {/*
*/}

zakiz via StackOverflow

unread,
Jan 27, 2014, 7:47:51 AM1/27/14
to google-appengin...@googlegroups.com

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

zakiz via StackOverflow

unread,
Jan 30, 2014, 5:03:36 AM1/30/14
to google-appengin...@googlegroups.com

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.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/21312172/import-json-from-app-engine-to-google-spreadsheet/21453143#21453143
Reply all
Reply to author
Forward
0 new messages