Search in sources :

Example 1 with NetHttpTransport

use of com.google.api.client.http.javanet.NetHttpTransport in project zeppelin by apache.

the class BigQueryInterpreter method createAuthorizedClient.

//Function that Creates an authorized client to Google Bigquery.
private static Bigquery createAuthorizedClient() throws IOException {
    HttpTransport transport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();
    GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
    if (credential.createScopedRequired()) {
        Collection<String> bigqueryScopes = BigqueryScopes.all();
        credential = credential.createScoped(bigqueryScopes);
    }
    return new Bigquery.Builder(transport, jsonFactory, credential).setApplicationName("Zeppelin/1.0 (GPN:Apache Zeppelin;)").build();
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) InterpreterPropertyBuilder(org.apache.zeppelin.interpreter.InterpreterPropertyBuilder) JsonFactory(com.google.api.client.json.JsonFactory) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Example 2 with NetHttpTransport

use of com.google.api.client.http.javanet.NetHttpTransport in project mobile-android by photo.

the class AccountTroveboxApiTest method testSignInViaGoogle.

public void testSignInViaGoogle() throws ClientProtocolException, IllegalStateException, IOException, JSONException, UserRecoverableAuthException, GoogleAuthException, GeneralSecurityException {
    // how to setup environment
    // http://android-developers.blogspot.in/2013/01/verifying-back-end-calls-from-android.html
    String[] names = getAccountNames();
    assertTrue(names != null && names.length > 0);
    String accountName = names[0];
    String audience = CommonUtils.getStringResource(R.string.google_auth_server_client_id);
    String SCOPE = "audience:server:client_id:" + audience;
    String tokenString = GoogleAuthUtil.getToken(getContext(), accountName, SCOPE);
    // token verification part, this should be done on server side
    GoogleIdTokenVerifier mVerifier;
    JsonFactory mJFactory;
    NetHttpTransport transport = new NetHttpTransport();
    mJFactory = new GsonFactory();
    mVerifier = new GoogleIdTokenVerifier(transport, mJFactory);
    GoogleIdToken token = GoogleIdToken.parse(mJFactory, tokenString);
    assertTrue(mVerifier.verify(token));
    GoogleIdToken.Payload tempPayload = token.getPayload();
    assertTrue(tempPayload.getAudience().equals(audience));
    assertNotNull(tempPayload.getEmail());
    // end of token verification part
    AccountTroveboxResponse response = mApi.signInViaGoogle(tokenString);
    assertNotNull(response);
    assertTrue(response.isSuccess());
    Credentials[] credentials = response.getCredentials();
    assertNotNull(credentials);
    assertTrue(credentials.length > 0);
    Credentials c = credentials[0];
    checkoAuthString(c.getoAuthConsumerKey());
    checkoAuthString(c.getoAuthConsumerSecret());
    checkoAuthString(c.getoAuthToken());
    checkoAuthString(c.getoAuthConsumerSecret());
}
Also used : GsonFactory(com.google.api.client.json.gson.GsonFactory) AccountTroveboxResponse(com.trovebox.android.app.net.account.AccountTroveboxResponse) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleIdTokenVerifier(com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier) JsonFactory(com.google.api.client.json.JsonFactory) GoogleIdToken(com.google.api.client.googleapis.auth.oauth2.GoogleIdToken) Credentials(com.trovebox.android.common.model.Credentials)

Example 3 with NetHttpTransport

use of com.google.api.client.http.javanet.NetHttpTransport in project cogcomp-nlp by CogComp.

the class QueryMQL method getResponse.

public JSONObject getResponse(String mqlQuery) throws IOException, ParseException {
    HttpTransport httpTransport = new NetHttpTransport();
    HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
    JSONParser parser = new JSONParser();
    GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
    url.put("query", mqlQuery);
    url.put("key", apikey);
    logger.debug("Querying Freebase QUERY URL: " + url.toString());
    HttpRequest request = requestFactory.buildGetRequest(url);
    HttpResponse httpResponse;
    try {
        httpResponse = request.execute();
    } catch (HttpResponseException e) {
        e.printStackTrace();
        int statusCode = e.getStatusCode();
        logger.error("StatusCode " + statusCode);
        logger.error("Query URL was " + url.toString());
        logger.error("Query was " + mqlQuery);
        if (// max limit reached for a day
        statusCode == 403) {
            System.exit(-1);
        }
        return null;
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        return null;
    }
    JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
    return response;
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(org.json.simple.JSONObject) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) JSONParser(org.json.simple.parser.JSONParser) HttpResponseException(com.google.api.client.http.HttpResponseException) GenericUrl(com.google.api.client.http.GenericUrl)

Example 4 with NetHttpTransport

use of com.google.api.client.http.javanet.NetHttpTransport in project cogcomp-nlp by CogComp.

the class QueryMQL method getCursorAndResponse.

public JSONObject getCursorAndResponse(String mqlQuery, String cursor) throws IOException, ParseException {
    HttpTransport httpTransport = new NetHttpTransport();
    HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
    JSONParser parser = new JSONParser();
    GenericUrl url = new GenericUrl("https://www.googleapis.com/freebase/v1/mqlread");
    url.put("query", mqlQuery);
    url.put("key", apikey);
    url.put("cursor", cursor);
    logger.debug("QUERY URL: " + url.toString());
    HttpRequest request = requestFactory.buildGetRequest(url);
    HttpResponse httpResponse = request.execute();
    JSONObject response = (JSONObject) parser.parse(httpResponse.parseAsString());
    return response;
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) JSONObject(org.json.simple.JSONObject) HttpRequestFactory(com.google.api.client.http.HttpRequestFactory) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpResponse(com.google.api.client.http.HttpResponse) JSONParser(org.json.simple.parser.JSONParser) GenericUrl(com.google.api.client.http.GenericUrl)

Example 5 with NetHttpTransport

use of com.google.api.client.http.javanet.NetHttpTransport in project local-data-aragopedia by aragonopendata.

the class GoogleDriveAPI method authorize.

private static GoogleCredential authorize() throws IOException, GeneralSecurityException {
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();
    GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(Prop.acountId).setServiceAccountScopes(SCOPES).setServiceAccountPrivateKeyFromP12File(new java.io.File(Prop.p12File)).build();
    return credential;
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) File(com.google.api.services.drive.model.File)

Aggregations

NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)12 HttpTransport (com.google.api.client.http.HttpTransport)9 GenericUrl (com.google.api.client.http.GenericUrl)7 HttpRequest (com.google.api.client.http.HttpRequest)7 HttpResponse (com.google.api.client.http.HttpResponse)6 IOException (java.io.IOException)5 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)4 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)4 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)4 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)3 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)3 JsonFactory (com.google.api.client.json.JsonFactory)2 File (com.google.api.services.drive.model.File)2 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 Test (org.junit.Test)2 AuthorizationCodeFlow (com.google.api.client.auth.oauth2.AuthorizationCodeFlow)1