コード例 #1
0
  // Note that this method makes a synchronous Graph API call, so should not be called from the main
  // thread.
  public static FetchedAppSettings queryAppSettings(
      final String applicationId, final boolean forceRequery) {

    // Cache the last app checked results.
    if (!forceRequery && fetchedAppSettings.containsKey(applicationId)) {
      return fetchedAppSettings.get(applicationId);
    }

    Bundle appSettingsParams = new Bundle();
    appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS));

    Request request = Request.newGraphPathRequest(null, applicationId, null);
    request.setParameters(appSettingsParams);

    GraphObject supportResponse = request.executeAndWait().getGraphObject();
    FetchedAppSettings result =
        new FetchedAppSettings(
            safeGetBooleanFromResponse(supportResponse, SUPPORTS_ATTRIBUTION),
            safeGetBooleanFromResponse(supportResponse, SUPPORTS_IMPLICIT_SDK_LOGGING),
            safeGetStringFromResponse(supportResponse, NUX_CONTENT),
            safeGetBooleanFromResponse(supportResponse, NUX_ENABLED));

    fetchedAppSettings.put(applicationId, result);

    return result;
  }
コード例 #2
0
  private void query(JSONArray args, CallbackContext callbackContext) throws JSONException {
    Log.d(TAG, "executing query: " + args.getString(0));

    Request request = new Request(Session.getActiveSession(), args.getString(0));

    Response response = request.executeAndWait();

    if (response.getError() != null) {
      callbackContext.error(response.getError().toString());
    } else {
      callbackContext.success(response.getGraphObject().getInnerJSONObject());
    }
  }
コード例 #3
0
  @Override
  protected Void doInBackground(Void... voids) {
    final VKRequest vkRequest = Requests.vkFriendsRequest(Requests.LOCALE_RUS);

    vkRequest.executeWithListener(
        new VKRequest.VKRequestListener() {
          @Override
          public void onComplete(VKResponse response) {
            super.onComplete(response);
            vkTask = new ParseVkResponseTask(vkFriends, listener, response);
            vkTask.setShowResults(false);
            vkTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
          }
        });

    while (vkTask == null) {}

    try {
      vkTask.get();
      Request fbRequest = Requests.fbFriendsRequest();
      Response response = fbRequest.executeAndWait();
      fbTask = new ParseFbResponseTask(fbFriends, listener, response);
      fbTask.setShowResults(false);
      Handler mainHandler = new Handler(Looper.getMainLooper());
      mainHandler.post(
          new Runnable() {
            @Override
            public void run() {
              fbTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
          });
      fbTask.get();
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }

    fillSyncContactsList();
    storeSyncContacts();

    return null;
  }
コード例 #4
0
  private void publish(JSONArray args, CallbackContext callbackContext) throws JSONException {
    JSONObject actionParams = args.getJSONObject(0);

    if (actionParams.has("object")) {
      RequestBatch requestBatch = new RequestBatch();

      OpenGraphObject object = buildOpenGraphObject(actionParams);

      Request objectRequest =
          Request.newPostOpenGraphObjectRequest(Session.getActiveSession(), object, null);
      objectRequest.setBatchEntryName("objectCreate");

      OpenGraphAction action =
          OpenGraphAction.Factory.createForPost(actionParams.getString("action"));

      action.setMessage(actionParams.getString("message"));
      action.setProperty("place", actionParams.getLong("place"));
      action.setExplicitlyShared(actionParams.getBoolean("explicitlyShared"));
      action.setProperty(actionParams.getString("objectType"), "{result=objectCreate:$.id}");

      Request request =
          Request.newPostOpenGraphActionRequest(Session.getActiveSession(), action, null);
      request.setBatchEntryDependsOn("objectCreate");

      requestBatch.add(objectRequest);
      requestBatch.add(request);

      List<Response> responses = requestBatch.executeAndWait();
      Response lastResponse = null;

      for (Response response : responses) {

        if (response.getError() != null) {
          callbackContext.error(response.getError().toString());
          return;
        }

        lastResponse = response;
      }

      callbackContext.success(lastResponse.getGraphObject().getInnerJSONObject());
    } else {
      OpenGraphAction action =
          OpenGraphAction.Factory.createForPost(actionParams.getString("action"));

      action.setMessage(actionParams.getString("message"));
      action.setProperty("place", actionParams.getLong("place"));
      action.setExplicitlyShared(actionParams.getBoolean("explicitlyShared"));
      action.setProperty(actionParams.getString("objectType"), actionParams.getString("objectId"));

      Request request =
          Request.newPostOpenGraphActionRequest(Session.getActiveSession(), action, null);

      Response response = request.executeAndWait();

      if (response.getError() != null) {
        callbackContext.error(response.getError().toString());
      } else {
        callbackContext.success(response.getGraphObject().getInnerJSONObject());
      }
    }
  }