示例#1
0
  private static AuthCredentials defaultAuthCredentials() {
    // Consider App Engine. This will not be needed once issue #21 is fixed.
    if (appEngineAppId() != null) {
      try {
        return AuthCredentials.createForAppEngine();
      } catch (Exception ignore) {
        // Maybe not on App Engine
      }
    }

    try {
      return AuthCredentials.createApplicationDefaults();
    } catch (Exception ex) {
      // fallback to old-style
    }

    // Consider old-style Compute. This will not be needed once issue #21 is fixed.
    try {
      return AuthCredentials.createForComputeEngine();
    } catch (Exception ignore) {
      // Maybe not on GCE
    }
    return AuthCredentials.noCredentials();
  }