OAuth2 Google Api java/eclipse -
im new java pelase bare me.. im looking @ example: https://developers.google.com/admin-sdk/directory/v1/quickstart/quickstart-java
but don't want use url copy/paste version auth iv'e read should use serviceaccount.
i downloaded p12 key , placed in source folder. , im rebuilding google example code found on stackoverflow
so here's how far get:
public class directorycommandline { httptransport httptransport = new nethttptransport(); jacksonfactory jsonfactory = new jacksonfactory(); // build service account credential. googlecredential credential = new googlecredential.builder().settransport(httptransport) .setjsonfactory(jsonfactory) .setserviceaccountid("......82p@developer.gserviceaccount.com") .setserviceaccountscopes(directoryscopes.all()) .setserviceaccountprivatekeyfromp12file(new java.io.file("eclipsejava-d6675et3ab71.p12")) .build(); // create new authorized api client directory service = new directory.builder(httptransport, jsonfactory, credential) .setapplicationname("directorycommandline") .build(); list<user> allusers = new arraylist<user>(); directory.users.list request = service.users().list().setcustomer("my_customer"); // users { try { users currentpage = request.execute(); allusers.addall(currentpage.getusers()); request.setpagetoken(currentpage.getnextpagetoken()); } catch (ioexception e) { system.out.println("an error occurred: " + e); request.setpagetoken(null); } } while (request.getpagetoken() != null && request.getpagetoken().length() > 0 ); // print users (user currentuser : allusers) { system.out.println(currentuser.getprimaryemail()); } } }
if run error:
error: main method not found in class directorycommandline, please define main method as: public static void main(string[] args)
i guess need add
public static void main(string[] args) throws ioexception {
infront/before:
httptransport httptransport = new nethttptransport(); jacksonfactory jsonfactory = new jacksonfactory();
but gets mess:
this has nothing google apis java class structure. considering beginner in java should start more simple exercises.
oracle , internet provide lot of documentation java. can start looking @ these links example : https://docs.oracle.com/javase/tutorial/getstarted/application/ https://docs.oracle.com/javase/tutorial/java/javaoo/classes.html
Comments
Post a Comment