Google Plus credentials for application Login -
i creating app , want confirm user using google credentials in java environment. can done using google api not sure how code servlet.
i found code snippet authorize credentials authorizationcodeinstalledapp() throwing error , not sure api use.
private static credential authorize() throws exception { // load client secrets googleclientsecrets clientsecrets = googleclientsecrets.load(json_factory, new inputstreamreader(test.class.getresourceasstream("/client_secrets.json"))); if (clientsecrets.getdetails().getclientid().startswith("enter") || clientsecrets.getdetails().getclientsecret().startswith("enter ")) { system.out.println( "enter client id , secret https://code.google.com/apis/console/?api=plus " + "into plus-cmdline-sample/src/main/resources/client_secrets.json"); system.exit(1); } // set authorization code flow googleauthorizationcodeflow flow = new googleauthorizationcodeflow.builder( httptransport, json_factory, clientsecrets, collections.singleton(plusscopes.plus_me)).setdatastorefactory( datastorefactory).build(); // authorize return new authorizationcodeinstalledapp(flow, new localserverreceiver()).authorize("user"); }
hope can me , let me know process it'll great...
if writing servlet run under google appengine, much easier that.
import com.google.appengine.api.users.user; import com.google.appengine.api.users.userservice; import com.google.appengine.api.users.userservicefactory; ... @override public void doget(httpservletrequest req, httpservletresponse resp) throws ioexception, servletexception { userservice userservice = userservicefactory.getuserservice(); user currentuser = userservice.getcurrentuser(); if (currentuser == null) { resp.sendredirect(userservice.createloginurl(req.getrequesturi())); } else { // show view } }
Comments
Post a Comment