com.google.api.client.extensions.android.json.AndroidJsonFactory Java Examples

The following examples show how to use com.google.api.client.extensions.android.json.AndroidJsonFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GAEService.java    From security-samples with Apache License 2.0 6 votes vote down vote up
private void initFido2GAEService() {
    if (fido2Service != null) {
        return;
    }
    if (googleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingAudience(
                    context, "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(googleSignInAccount.getEmail());
    Log.d(TAG, "credential account name " + credential.getSelectedAccountName());

    Fido2RequestHandler.Builder builder =
            new Fido2RequestHandler.Builder(
                    AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), credential)
                    .setGoogleClientRequestInitializer(
                            new GoogleClientRequestInitializer() {
                                @Override
                                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                        throws IOException {
                                    abstractGoogleClientRequest.setDisableGZipContent(true);
                                }
                            });
    fido2Service = builder.build();
}
 
Example #2
Source File: GAEService.java    From android-fido with Apache License 2.0 6 votes vote down vote up
private void initFido2GAEService() {
    if (fido2Service != null) {
        return;
    }
    if (googleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingAudience(
                    context, "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(googleSignInAccount.getEmail());
    Log.d(TAG, "credential account name " + credential.getSelectedAccountName());

    Fido2RequestHandler.Builder builder =
            new Fido2RequestHandler.Builder(
                    AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), credential)
                    .setGoogleClientRequestInitializer(
                            new GoogleClientRequestInitializer() {
                                @Override
                                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                        throws IOException {
                                    abstractGoogleClientRequest.setDisableGZipContent(true);
                                }
                            });
    fido2Service = builder.build();
}
 
Example #3
Source File: MainActivity.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected String doInBackground(String... params) {
    if (myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("https://YOUR-PROJECT-ID.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver
        myApiService = builder.build();
    }

    try {
        return myApiService.sayHi(params[0]).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
Example #4
Source File: MainActivity.java    From android-docs-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected String doInBackground(String... params) {
    if (myApiService == null) {  // Only do this once
        MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                .setRootUrl("http://YOUR-PROJECT-ID.appspot.com/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end options for devappserver
        myApiService = builder.build();
    }

    try {
        return myApiService.sayHi(params[0]).execute().getData();
    } catch (IOException e) {
        return e.getMessage();
    }
}
 
Example #5
Source File: CloudEndpointBuilderHelper.java    From MobileShoppingAssistant-sample with Apache License 2.0 6 votes vote down vote up
/**
 * *
 *
 * @return ShoppingAssistant endpoints to the GAE backend.
 */
static ShoppingAssistant getEndpoints() {

    // Create API handler
    ShoppingAssistant.Builder builder = new ShoppingAssistant.Builder(
            AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), getRequestInitializer())
            .setRootUrl(Constants.ROOT_URL)
            .setGoogleClientRequestInitializer(
                    new GoogleClientRequestInitializer() {
                        @Override
                        public void initialize(
                                final AbstractGoogleClientRequest<?>
                                        abstractGoogleClientRequest)
                                throws IOException {
                            abstractGoogleClientRequest
                                    .setDisableGZipContent(true);
                        }
                    }
            );

    return builder.build();
}
 
Example #6
Source File: EndpointsTaskBagImpl.java    From endpoints-codelab-android with GNU General Public License v3.0 6 votes vote down vote up
public EndpointsTaskBagImpl(TodoPreferences preferences,
                            LocalTaskRepository localRepository) {
    super(preferences, localRepository, null);

    // Production testing
    //TaskApi.Builder builder = new TaskApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null);

    // Local testing
    TaskApi.Builder builder = new TaskApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
            .setRootUrl("http://10.0.2.2:8080/_ah/api/")
            .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                @Override
                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
                    abstractGoogleClientRequest.setDisableGZipContent(true);
                }
            });

    taskApiService = builder.build();

}
 
Example #7
Source File: YouTubeAPI.java    From UTubeTV with The Unlicense 6 votes vote down vote up
public YouTube youTube() {
  if (youTube == null) {
    try {
      HttpRequestInitializer credentials;

      if (mUseAuthCredentials)
        credentials = Auth.getCredentials(mContext, mUseDefaultAccount);
      else
        credentials = Auth.nullCredentials(mContext);

      youTube = new YouTube.Builder(new NetHttpTransport(), new AndroidJsonFactory(), credentials).setApplicationName("YouTubeAPI")
          .build();
    } catch (Exception e) {
      e.printStackTrace();
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }

  return youTube;
}
 
Example #8
Source File: ReadWriteAdvertisementSlotDialogFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void shortenUrl(final String longUrl){
    if(!Utils.API_KEY.equals(Utils.UTILS_API_KEY)) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Urlshortener.Builder builder = new Urlshortener.Builder(AndroidHttp.newCompatibleTransport(), AndroidJsonFactory.getDefaultInstance(), null)
                            .setApplicationName(getString(R.string.app_name));
                    Urlshortener urlshortener = builder.build();
                    com.google.api.services.urlshortener.model.Url url = new Url();
                    url.setLongUrl(longUrl);
                    Urlshortener.Url.Insert insertUrl = urlshortener.url().insert(url);
                    insertUrl.setKey(Utils.API_KEY);
                    url = insertUrl.execute();
                    final String newUrl = url.getId();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            final SpannableString urlAttachment = new SpannableString(newUrl);
                            urlAttachment.setSpan(new UnderlineSpan(), 0, newUrl.length(), 0);
                            mUrlShortenerContainer.setVisibility(View.VISIBLE);
                            mUrl.setError(null);
                            mUrlShortText.setText(urlAttachment.toString());
                            mIsUrlExpanded = false;
                            mExpandedUrl = null;
                        }
                    });
                } catch (IOException ex) {
                    Log.v(Utils.TAG, ex.getMessage());
                }
            }
        }).start();
    }
    else {
        Toast.makeText(getActivity(), getString(R.string.api_key_error), Toast.LENGTH_LONG);
    }
}