com.facebook.FacebookRequestError Java Examples

The following examples show how to use com.facebook.FacebookRequestError. 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: ShareInternalUtility.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static void invokeCallbackWithResults(
        FacebookCallback<Sharer.Result> callback,
        final String postId,
        final GraphResponse graphResponse) {
    FacebookRequestError requestError = graphResponse.getError();
    if (requestError != null) {
        String errorMessage = requestError.getErrorMessage();
        if (Utility.isNullOrEmpty(errorMessage)) {
            errorMessage = "Unexpected error sharing.";
        }
        invokeOnErrorCallback(callback, graphResponse, errorMessage);
    } else {
        invokeOnSuccessCallback(callback, postId);
    }
}
 
Example #2
Source File: VideoUploader.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
protected void executeGraphRequestSynchronously(Bundle parameters) {
    GraphRequest request = new GraphRequest(
            uploadContext.accessToken,
            String.format(Locale.ROOT, "%s/videos", uploadContext.graphNode),
            parameters,
            HttpMethod.POST,
            null);
    GraphResponse response = request.executeAndWait();

    if (response != null) {
        FacebookRequestError error = response.getError();
        JSONObject responseJSON = response.getJSONObject();
        if (error != null) {
            if (!attemptRetry(error.getSubErrorCode())) {
                handleError(new FacebookGraphResponseException(response, ERROR_UPLOAD));
            }
        } else if (responseJSON != null) {
            try {
                handleSuccess(responseJSON);
            } catch (JSONException e) {
                endUploadWithFailure(new FacebookException(ERROR_BAD_SERVER_RESPONSE, e));
            }
        } else {
            handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE));
        }
    } else {
        handleError(new FacebookException(ERROR_BAD_SERVER_RESPONSE));
    }
}
 
Example #3
Source File: FacebookRequestErrorClassification.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public String getRecoveryMessage(FacebookRequestError.Category category) {
    switch (category) {
        case OTHER:
            return otherRecoveryMessage;
        case LOGIN_RECOVERABLE:
            return loginRecoverableRecoveryMessage;
        case TRANSIENT:
            return transientRecoveryMessage;
        default:
            return null;
    }
}
 
Example #4
Source File: FiscalizacaoConcluidaActivity.java    From vocefiscal-android with Apache License 2.0 5 votes vote down vote up
private void publishStory(Session session) 
{
	Bundle postParams = new Bundle();
	postParams.putString("name", "Você Fiscal");

	// Receber os dados da eleição!!!
	postParams.putString("message", "Eu fiscalizei a seção: "+ this.secao +"\nNa zona eleitoral: " + this.zonaEleitoral + "\nNo município de: " + this.municipio);			
	postParams.putString("description", "Obrigado por contribuir com a democracia!");
	postParams.putString("link", "http://www.vocefiscal.org/");
	postParams.putString("picture", "http://imagizer.imageshack.us/v2/150x100q90/913/bAwPgx.png");

	Request.Callback callback= new Request.Callback() 
	{
		public void onCompleted(Response response) 
		{
			JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
			String postId = "Compartilhado com sucesso!";
			try 
			{
				postId = graphResponse.getString("Compartilhado com sucesso!");
			} catch (JSONException e) 
			{
			}
			FacebookRequestError error = response.getError();
			if (error != null) 
			{
				Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),error.getErrorMessage(),Toast.LENGTH_SHORT).show();
			} else 
			{
				Toast.makeText(FiscalizacaoConcluidaActivity.this.getApplicationContext(),	postId,	Toast.LENGTH_LONG).show();
			}
		}
	};

	Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);

	RequestAsyncTask task = new RequestAsyncTask(request);
	task.execute();
}
 
Example #5
Source File: WebViewLoginMethodHandler.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
void onWebDialogComplete(LoginClient.Request request, Bundle values,
        FacebookException error) {
    LoginClient.Result outcome;
    if (values != null) {
        // Actual e2e we got from the dialog should be used for logging.
        if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
            e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
        }

        try {
            AccessToken token = createAccessTokenFromWebBundle(
                    request.getPermissions(),
                    values,
                    AccessTokenSource.WEB_VIEW,
                    request.getApplicationId());
            outcome = LoginClient.Result.createTokenResult(
                    loginClient.getPendingRequest(),
                    token);

            // Ensure any cookies set by the dialog are saved
            // This is to work around a bug where CookieManager may fail to instantiate if
            // CookieSyncManager has never been created.
            CookieSyncManager syncManager =
                    CookieSyncManager.createInstance(loginClient.getActivity());
            syncManager.sync();
            saveCookieToken(token.getToken());
        } catch (FacebookException ex) {
            outcome = LoginClient.Result.createErrorResult(
                    loginClient.getPendingRequest(),
                    null,
                    ex.getMessage());
        }
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(),
                    "User canceled log in.");
        } else {
            // Something went wrong, don't log a completion event since it will skew timing
            // results.
            e2e = null;

            String errorCode = null;
            String errorMessage = error.getMessage();
            if (error instanceof FacebookServiceException) {
                FacebookRequestError requestError =
                        ((FacebookServiceException)error).getRequestError();
                errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
                errorMessage = requestError.toString();
            }
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(),
                    null, errorMessage, errorCode);
        }
    }

    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }

    loginClient.completeAndValidate(outcome);
}
 
Example #6
Source File: AppEventsLogger.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
private static void handleResponse(
        AccessTokenAppIdPair accessTokenAppId,
        GraphRequest request,
        GraphResponse response,
        SessionEventsState sessionEventsState,
        FlushStatistics flushState) {
    FacebookRequestError error = response.getError();
    String resultDescription = "Success";

    FlushResult flushResult = FlushResult.SUCCESS;

    if (error != null) {
        final int NO_CONNECTIVITY_ERROR_CODE = -1;
        if (error.getErrorCode() == NO_CONNECTIVITY_ERROR_CODE) {
            resultDescription = "Failed: No Connectivity";
            flushResult = FlushResult.NO_CONNECTIVITY;
        } else {
            resultDescription = String.format("Failed:\n  Response: %s\n  Error %s",
                    response.toString(),
                    error.toString());
            flushResult = FlushResult.SERVER_ERROR;
        }
    }

    if (FacebookSdk.isLoggingBehaviorEnabled(LoggingBehavior.APP_EVENTS)) {
        String eventsJsonString = (String) request.getTag();
        String prettyPrintedEvents;

        try {
            JSONArray jsonArray = new JSONArray(eventsJsonString);
            prettyPrintedEvents = jsonArray.toString(2);
        } catch (JSONException exc) {
            prettyPrintedEvents = "<Can't encode events for debug logging>";
        }

        Logger.log(LoggingBehavior.APP_EVENTS, TAG,
                "Flush completed\nParams: %s\n  Result: %s\n  Events JSON: %s",
                request.getGraphObject().toString(),
                resultDescription,
                prettyPrintedEvents);
    }

    sessionEventsState.clearInFlightAndStats(error != null);

    if (flushResult == FlushResult.NO_CONNECTIVITY) {
        // We may call this for multiple requests in a batch, which is slightly inefficient
        // since in principle we could call it once for all failed requests, but the impact is
        // likely to be minimal. We don't call this for other server errors, because if an event
        // failed because it was malformed, etc., continually retrying it will cause subsequent
        // events to not be logged either.
        PersistedEvents.persistEvents(applicationContext, accessTokenAppId, sessionEventsState);
    }

    if (flushResult != FlushResult.SUCCESS) {
        // We assume that connectivity issues are more significant to report than server issues.
        if (flushState.result != FlushResult.NO_CONNECTIVITY) {
            flushState.result = flushResult;
        }
    }
}
 
Example #7
Source File: FacebookShareActivity.java    From FacebookImageShareIntent with MIT License 4 votes vote down vote up
private void addNotification(String message, GraphObject result, FacebookRequestError error)
{
    String title = null;
    String alertMessage = null;
    if (error == null) {
        title = getString(R.string.success);
        String id = result.cast(GraphObjectWithId.class).getId();
        alertMessage = getString(R.string.successfully_posted_post, message, id);
    } else {
        title = getString(R.string.error);
        alertMessage = error.getErrorMessage();
    }

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(title)
                    .setContentText(alertMessage);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    int mId = 0;
    mNotificationManager.notify(mId, mBuilder.build());
}