Java sample OAuth service flow apps for accessing Big Query -


is there sample java apps show how access big query using oauth service flow. of apps seem show web , desktop flows.

thanks

sure - try (below). more examples of type of flow here: https://developers.google.com/bigquery/authorization#service-accounts-server

import com.google.api.client.http.httptransport; import com.google.api.client.http.javanet.nethttptransport; import com.google.api.client.json.jsonfactory; import com.google.api.client.json.jackson.jacksonfactory;  import com.google.api.client.googleapis.auth.oauth2.googlecredential; import com.google.api.services.bigquery.bigquery; import com.google.api.services.bigquery.bigquery.datasets; import com.google.api.services.bigquery.model.datasetlist;  import java.io.file; import java.io.ioexception; import java.security.generalsecurityexception;  public class javacommandlineserviceaccounts {    private static final string scope = "https://www.googleapis.com/auth/bigquery";   private static final httptransport transport = new nethttptransport();   private static final jsonfactory json_factory = new jacksonfactory();    private static bigquery bigquery;    public static void main(string[] args) throws ioexception, generalsecurityexception {     googlecredential credential = new googlecredential.builder().settransport(transport)         .setjsonfactory(json_factory)         .setserviceaccountid("xxxxxxx@developer.gserviceaccount.com")         .setserviceaccountscopes(scope)         .setserviceaccountprivatekeyfromp12file(new file("my_file.p12"))         .build();      bigquery = new bigquery.builder(transport, json_factory, credential)         .setapplicationname("bigquery-service-accounts/0.1")         .sethttprequestinitializer(credential).build();      datasets.list datasetrequest = bigquery.datasets().list("publicdata");     datasetlist datasetlist = datasetrequest.execute();     system.out.format("%s\n", datasetlist.toprettystring());   }  } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -