Get access google spreadsheet (saved into google drive account) from a java google app engine (servlet) -


i stuck here. want access google spreadsheet google app engine (with java, using servlet because idea read information spreadsheet, saved in google drive account, , shows via "jsp" limited users number, here in company).

of course i've create project in "google cloud developer console" got "project id" fourth-case-xxxx, etc . until step understood , went well.

i´ve been looking thousands of example here , on google, etc.for read understand that: must create "oauth2 credential" (reason why created oauth2 credential in "api , authentication" in developer console of course (i got json auth_uri, client_secret, client_id, etc, etc).

from i've read need client_secret , client_id. following tutorial (link) got error "oauth_token not exist.". in other tutorial i´v read not necessary use "oauth2" in app engine. dizzy.

the want simple java servlet (nothing complex, following practices, not care) read data google spreadsheet (saved google drive account) , showing through "jsp", @ least content accept receiving spreadsheet data on servlet , later imagine how show

i´m ussing eclipse luna, got installed "gdata java api", "google app engine localhost", etc (all installed, running without errors). create ambient followed this tutorial

some questions: 1-the spreadsheet need published? (menu: file->publish web). acces app engine? 2-to test code (and if got access spreadhsheet) in mandatory uploading google app engine (http://.appspot.com/guestbook) or can try "localhost"?

i upload code, attached image etc. apologize nasty code need solve issue

thanks all

public void callingspreadsheettest2() throws ioexception {     system.out.println("callingspreadsheettest2");     httptransport  transport = new nethttptransport();     jacksonfactory jsonfactory = new jacksonfactory();      googleoauthparameters oauthparameters = new googleoauthparameters();     oauthparameters.setoauthconsumerkey(client_id);     oauthparameters.setoauthconsumersecret(client_secret);      oauthhmacsha1signer signer = new oauthhmacsha1signer();     googleoauthhelper oauthhelper = new googleoauthhelper(signer);      oauthparameters.setscope(scopes);      try{         oauthhelper.getunauthorizedrequesttoken(oauthparameters);     }catch (oauthexception e){         e.printstacktrace();     }      string requesturl = oauthhelper.createuserauthorizationurl(oauthparameters);     system.out.println(requesturl);     system.out.println("please visit url above authorize oauth "      + "request token.  once complete, press key "      + "continue...");      try{         system.in.read();     }catch(ioexception e){         e.printstacktrace();     }     oauthparameters.setoauthtype(oauthtype.two_legged_oauth);     string token = null;     try{         token = oauthhelper.getaccesstoken(oauthparameters);     }catch(oauthexception  e){         e.printstacktrace(); //---->attention: here got toke=null (oauth_token not exist.)     }     system.out.println("oauth access token: " + token);     system.out.println();      url feedurl = null;      try{         feedurl = new url(spreadsheet_url);     }catch(malformedurlexception e){         e.printstacktrace();     }      spreadsheetservice spreadsheetservice = new spreadsheetservice("gappengineproj");      try{         spreadsheetservice.setoauthcredentials(oauthparameters, signer);     }catch(oauthexception e){         e.printstacktrace();     }      try {         spreadsheetfeed feed = spreadsheetservice.getfeed(feedurl, spreadsheetfeed.class);         list<spreadsheetentry> spreadsheets = feed.getentries();         if(spreadsheets != null) {                           (spreadsheetentry spreadsheet : spreadsheets) {                   system.out.println(spreadsheet.gettitle().getplaintext());               }          }     } catch (serviceexception e) {         e.printstacktrace();     } 

also class "com.google.gdata.client.spreadsheet.spreadsheetservice" not have method setoauth2credentials [service.setoauthcredentials(parameters, signer);]

once again thanks!!

you're using code oauth1 protocol, deprecated. should use oauth2 instead.

an app engine application comes convenient appidentityservice (documentation) allows application generate oauth2 tokens if application had email in format your-project-id@appspot.gserviceaccount.com.

all have share spreadsheet email using google drive / google spreadsheets ui. in case email fourth-case-xxxx@appspot.gserviceaccount.com

then, in code, :

appidentityservice appidentity = appidentityservicefactory.getappidentityservice(); string accesstoken = appidentityservice.getaccesstoken(collections.singleton(spreadsheet_scope)).getaccesstoken(); googlecredential googlecredential = new googlecredential(); googlecredential.setaccesstoken(accesstoken); spreadsheetservice = new spreadsheetservice("myapp"); spreadsheetservice.setoauth2credentials(buildcredential()); 

then ready use spreadsheetservice read data.

nb : code written gdata library version 1.47.1 .


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -