Get com.google.gdata.util.ServiceForbiddenException after moving contact sync app to new machine -
i have java application uses google contact api sync contacts a local pda application. working fine on old machine, after copying source , (including client_secrets.json) new laptop, following error calling com.google.gdata.client.service.getfeed():
com.google.gdata.util.serviceforbiddenexception: cannot request contacts belonging user
i passing in same user id , password before, i'm not sure why says "another user".
here's relevant code:
// initialize contacts service service = new contactsservice(cfg.gappname); // authorize service credential credential = authorize(contacts_scope, "contacts"); if (credential != null && (credential.getexpiresinseconds() == null || credential.getexpiresinseconds() < 5)) { credential.refreshtoken(); } string token = credential.getaccesstoken(); service.setheader("authorization", "bearer " + token); // request feed contfeedurl = new url(base_cont_url + contacts + cfg.guser + "/full?max-results=999999"); if (bfeed) { resultfeed = service.getfeed(contfeedurl, contactfeed.class); }
and authorize() method:
protected credential authorize(string scope, string subdir) throws exception { file datastoredir = new file(system.getproperty("user.home"), ".store/gsync/" + cfg.datastore + "/" + subdir); // initialize transport httptransport = googlenethttptransport.newtrustedtransport(); // initialize data store factory datastorefactory = new filedatastorefactory(datastoredir); // load client secrets googleclientsecrets clientsecrets = googleclientsecrets.load(json_factory, new inputstreamreader(syncmgr.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=calendar " + "into /client_secrets.json"); system.exit(1); } // set authorization code flow googleauthorizationcodeflow flow = new googleauthorizationcodeflow.builder( httptransport, json_factory, clientsecrets, collections.singleton(scope)).setdatastorefactory(datastorefactory).build(); // authorize return new authorizationcodeinstalledapp(flow, new localserverreceiver()).authorize(cfg.guser); }
any ideas how can working on new machine?
Comments
Post a Comment