Hacker News new | past | comments | ask | show | jobs | submit login

    GOOGLE PLUS
    GOOGLE
    ALPHABET



It's much more beautiful if you use Android SDK:

  private boolean googleSubsidiaryConnectionSuccess = false;
  private boolean googleSubsidiaryConnectionInProgress = false;
  private GoogleSubsidiary googleSubsidiary = null;
  private GoogleVideoHostingManager googleVideoHostingService = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
     GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this)
          .addSubsidiary(AlphabetSubsidiaries.GOOGLE_SUBSIDIARY);
     GoogleApiClient client = builder.build();
     client.connect();
     googleSubsidiaryConnectionInProgress = true;
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data /* ignored */) {
     if (requestCode == GoogleSubsidiary.EXISTS_AND_IS_PROFITABLE) { // actual value is -11
          if (responseCode != Activity.RESULT_OK) {
              Log.w(TAG, "could not get subsidiary");
              googleSubsidiaryConnectionSuccess = false;
              if (!client.isConnecting()) {
                  Log.v(TAG, "calling googleApiClient.connect again");
                  client.connect();
              }
          }
      } else {
          Log.w(TAG, "Google subsidiary may be out of business. Not sure.");
          if (!googleSubsidiaryConnectionInProgress && !client.isConnecting()) {
               client.connect();
          }
      }
  }
  
  @Override
  public void onConnected(Bundle connectionHint) {
     googleSubsidiaryConnectionSuccess = true;
     googleSubsidiaryConnectionInProgress = false;
     GoogleSubsidiaryToken googleSubsidiaryToken = GoogleSubsidiaryUtil.getToken(activity, GOOGLE_SUBSIDIARY_TOKEN_REQUEST_SCOPE);
     try {
          googleSubsidiary = (GoogleSubsidiary)GoogleSubsidiaryUtil.getSubsidiaryObjectFromToken(googleSubsidiaryToken);
          googleVideoHostingService = (GoogleVideoHostingManager)googleSubsidiary.getService(GoogleSubsidiary.YOU_TUBE_SERVICE);
          if (googleVideoHostingService == null && !client.isConnecting()) {
               client.connect();
          }
     } catch (SubsidiaryTokenOutOfDateException ex) {
          googleSubsidiaryConnectionSuccess = false;
          if (!client.isConnecting()) {
               client.connect();
          }
     }
  }




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: