Ejemplo n.º 1
0
    @Override
    protected JSONObject doInBackground(Void... params) {
      JSONObject json = null;
      try {
        authToken = GoogleAuthUtil.getToken(main, "*****@*****.**", "oauth2:email");

        String path = "submitWhite/" + gameId;

        ArrayList<BasicNameValuePair> values = new ArrayList<BasicNameValuePair>();
        values.add(
            new BasicNameValuePair("whiteCardIdsJson", new JSONArray(whiteCardIds).toString()));

        json = httpEndpointsHandler.post(path, authToken, true, values);
      } catch (UserRecoverableAuthException e) {
        main.startActivityForResult(e.getIntent(), MainActivity.AUTH_REQUEST_CODE);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (GoogleAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return json;
    }
Ejemplo n.º 2
0
    @Override
    protected String doInBackground(Void... params) {
      try {
        if (isCancelled()) {
          LOGD(TAG, "doInBackground: task cancelled, so giving up on auth.");
          return null;
        }

        LOGD(TAG, "Starting background auth for " + mAccountName);
        final String token = GoogleAuthUtil.getToken(mAppContext, mAccountName, AUTH_TOKEN_TYPE);

        // Save auth token.
        LOGD(
            TAG,
            "Saving token: "
                + (token == null ? "(null)" : "(length " + token.length() + ")")
                + " for account "
                + mAccountName);
        AccountUtils.setAuthToken(mAppContext, mAccountName, token);
        return token;
      } catch (GooglePlayServicesAvailabilityException e) {
        postShowRecoveryDialog(e.getConnectionStatusCode());
      } catch (UserRecoverableAuthException e) {
        postShowAuthRecoveryFlow(e.getIntent());
      } catch (IOException e) {
        LOGE(TAG, "IOException encountered: " + e.getMessage());
      } catch (GoogleAuthException e) {
        LOGE(TAG, "GoogleAuthException encountered: " + e.getMessage());
      } catch (RuntimeException e) {
        LOGE(TAG, "RuntimeException encountered: " + e.getMessage());
      }
      return null;
    }
    @Override
    protected HashMap<String, String> doInBackground(Long... values) {

      mResults = new HashMap<String, String>();

      String selection = InstanceColumns._ID + "=?";
      String[] selectionArgs = new String[(values == null) ? 0 : values.length];
      if (values != null) {
        for (int i = 0; i < values.length; i++) {
          if (i != values.length - 1) {
            selection += " or " + InstanceColumns._ID + "=?";
          }
          selectionArgs[i] = values[i].toString();
        }
      }

      String token = null;
      try {
        token = authenticate(GoogleMapsEngineUploaderActivity.this, mGoogleUserName);
      } catch (IOException e) {
        // network or server error, the call is expected to succeed if
        // you try again later. Don't attempt to call again immediately
        // - the request is likely to fail, you'll hit quotas or
        // back-off.
        e.printStackTrace();
        mResults.put("0", oauth_fail + e.getMessage());
        return mResults;
      } catch (GooglePlayServicesAvailabilityException playEx) {
        Dialog alert =
            GooglePlayServicesUtil.getErrorDialog(
                playEx.getConnectionStatusCode(),
                GoogleMapsEngineUploaderActivity.this,
                PLAYSTORE_REQUEST_CODE);
        alert.show();
        return null;
      } catch (UserRecoverableAuthException e) {
        GoogleMapsEngineUploaderActivity.this.startActivityForResult(
            e.getIntent(), USER_RECOVERABLE_REQUEST_CODE);
        e.printStackTrace();
        return null;
      } catch (GoogleAuthException e) {
        // Failure. The call is not expected to ever succeed so it
        // should not be retried.
        e.printStackTrace();
        mResults.put("0", oauth_fail + e.getMessage());
        return mResults;
      }

      if (token == null) {
        // if token is null,
        return null;
      }

      uploadInstances(selection, selectionArgs, token);
      return mResults;
    }
Ejemplo n.º 4
0
 @Override
 protected String doInBackground(String... params) {
   String accountName = params[0];
   String scopes = "oauth2:profile email";
   String token = null;
   try {
     token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
   } catch (IOException e) {
     Log.e(TAG, e.getMessage());
   } catch (UserRecoverableAuthException e) {
     startActivityForResult(e.getIntent(), REQUEST_CODE_TOKEN_AUTH);
   } catch (GoogleAuthException e) {
     Log.e(TAG, e.getMessage());
   }
   return token;
 }
Ejemplo n.º 5
0
    @Override
    protected JSONObject doInBackground(Void... params) {
      JSONObject json = null;
      try {
        authToken = GoogleAuthUtil.getToken(main, "*****@*****.**", "oauth2:email");

        String path = "fetchPlayers/" + gameId;

        json = httpEndpointsHandler.get(path, authToken, true, null);
      } catch (UserRecoverableAuthException e) {
        main.startActivityForResult(e.getIntent(), MainActivity.AUTH_REQUEST_CODE);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (GoogleAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return json;
    }
Ejemplo n.º 6
0
    @Override
    protected JSONObject doInBackground(String... params) {
      String path = "fetchCurrentSubmissions/" + gameId;

      JSONObject json = null;
      try {
        authToken = GoogleAuthUtil.getToken(main, "*****@*****.**", "oauth2:email");

        ArrayList<BasicNameValuePair> values = new ArrayList<BasicNameValuePair>();
        values.add(new BasicNameValuePair("status", Integer.toString(1)));

        json = httpEndpointsHandler.get(path, authToken, true, values);
      } catch (UserRecoverableAuthException e) {
        main.startActivityForResult(e.getIntent(), MainActivity.AUTH_REQUEST_CODE);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (GoogleAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return json;
    }