Java Refresh the access token to access google api -
when try run command refresh access token , access token value refreshed following error.please tell me how fix it
java.lang.nullpointerexception @ com.google.api.client.repackaged.com.google.common.base.preconditions.checknotnull(preconditions.java:191) @ com.google.api.client.util.preconditions.checknotnull(preconditions.java:127) @ com.google.api.client.googleapis.auth.oauth2.googlecredential.<init>(googlecredential.java:320) @ com.google.api.client.googleapis.auth.oauth2.googlecredential$builder.build(googlecredential.java:515) @ demo.newclass2.main(newclass2.java:38)
mycode : think because set missing googlecredential,so can't refresh token
public static void main(string[] args) { try { string refreshtoken = ""; string clientid = ""; string cliensecret = ""; string p12 = ""; httptransport http_transport = new nethttptransport(); jsonfactory json_factory = new jacksonfactory(); googlecredential credential = new googlecredential.builder() .settransport(http_transport) .setjsonfactory(json_factory) .setclientsecrets(clientid, cliensecret) .setserviceaccountprivatekeyfromp12file(new file(p12)) .setserviceaccountscopes(collections.singleton(bloggerscopes.blogger)) .build(); credential.setrefreshtoken(refreshtoken); credential.refreshtoken(); system.out.println(credential.getaccesstoken()); } catch (exception e) { e.printstacktrace(); } }
Comments
Post a Comment