Search in sources :

Example 11 with FacebookException

use of com.facebook.FacebookException in project facebook-android-sdk by facebook.

the class WebDialog method sendErrorToListener.

protected void sendErrorToListener(Throwable error) {
    if (onCompleteListener != null && !listenerCalled) {
        listenerCalled = true;
        FacebookException facebookException;
        if (error instanceof FacebookException) {
            facebookException = (FacebookException) error;
        } else {
            facebookException = new FacebookException(error);
        }
        onCompleteListener.onComplete(null, facebookException);
        dismiss();
    }
}
Also used : FacebookException(com.facebook.FacebookException)

Example 12 with FacebookException

use of com.facebook.FacebookException in project facebook-android-sdk by facebook.

the class CustomTabLoginMethodHandler method onCustomTabComplete.

private void onCustomTabComplete(String url, LoginClient.Request request) {
    if (url != null && url.startsWith(CustomTabMainActivity.getRedirectUrl())) {
        Uri uri = Uri.parse(url);
        Bundle values = Utility.parseUrlQueryString(uri.getQuery());
        values.putAll(Utility.parseUrlQueryString(uri.getFragment()));
        if (!validateChallengeParam(values)) {
            super.onComplete(request, null, new FacebookException("Invalid state parameter"));
            return;
        }
        String error = values.getString("error");
        if (error == null) {
            error = values.getString("error_type");
        }
        String errorMessage = values.getString("error_msg");
        if (errorMessage == null) {
            errorMessage = values.getString("error_message");
        }
        if (errorMessage == null) {
            errorMessage = values.getString("error_description");
        }
        String errorCodeString = values.getString("error_code");
        int errorCode = FacebookRequestError.INVALID_ERROR_CODE;
        if (!Utility.isNullOrEmpty(errorCodeString)) {
            try {
                errorCode = Integer.parseInt(errorCodeString);
            } catch (NumberFormatException ex) {
                errorCode = FacebookRequestError.INVALID_ERROR_CODE;
            }
        }
        if (Utility.isNullOrEmpty(error) && Utility.isNullOrEmpty(errorMessage) && errorCode == FacebookRequestError.INVALID_ERROR_CODE) {
            super.onComplete(request, values, null);
        } else if (error != null && (error.equals("access_denied") || error.equals("OAuthAccessDeniedException"))) {
            super.onComplete(request, null, new FacebookOperationCanceledException());
        } else if (errorCode == API_EC_DIALOG_CANCEL) {
            super.onComplete(request, null, new FacebookOperationCanceledException());
        } else {
            FacebookRequestError requestError = new FacebookRequestError(errorCode, error, errorMessage);
            super.onComplete(request, null, new FacebookServiceException(requestError, errorMessage));
        }
    }
}
Also used : FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) FacebookServiceException(com.facebook.FacebookServiceException) Uri(android.net.Uri) FacebookRequestError(com.facebook.FacebookRequestError)

Example 13 with FacebookException

use of com.facebook.FacebookException in project facebook-android-sdk by facebook.

the class DialogPresenter method setupAppCallForNativeDialog.

public static void setupAppCallForNativeDialog(AppCall appCall, ParameterProvider parameterProvider, DialogFeature feature) {
    Context context = FacebookSdk.getApplicationContext();
    String action = feature.getAction();
    NativeProtocol.ProtocolVersionQueryResult protocolVersionResult = getProtocolVersionForNativeDialog(feature);
    int protocolVersion = protocolVersionResult.getProtocolVersion();
    if (protocolVersion == NativeProtocol.NO_PROTOCOL_AVAILABLE) {
        throw new FacebookException("Cannot present this dialog. This likely means that the " + "Facebook app is not installed.");
    }
    Bundle params;
    if (NativeProtocol.isVersionCompatibleWithBucketedIntent(protocolVersion)) {
        // Facebook app supports the new bucketed protocol
        params = parameterProvider.getParameters();
    } else {
        // Facebook app only supports the old flat protocol
        params = parameterProvider.getLegacyParameters();
    }
    if (params == null) {
        params = new Bundle();
    }
    Intent intent = NativeProtocol.createPlatformActivityIntent(context, appCall.getCallId().toString(), action, protocolVersionResult, params);
    if (intent == null) {
        throw new FacebookException("Unable to create Intent; this likely means the" + "Facebook app is not installed.");
    }
    appCall.setRequestIntent(intent);
}
Also used : Context(android.content.Context) FacebookException(com.facebook.FacebookException) Bundle(android.os.Bundle) Intent(android.content.Intent)

Example 14 with FacebookException

use of com.facebook.FacebookException in project facebook-android-sdk by facebook.

the class DialogPresenter method setupAppCallForCannotShowError.

public static void setupAppCallForCannotShowError(AppCall appCall) {
    FacebookException e = new FacebookException("Unable to show the provided content via the web or the installed version of the " + "Facebook app. Some dialogs are only supported starting API 14.");
    setupAppCallForValidationError(appCall, e);
}
Also used : FacebookException(com.facebook.FacebookException)

Example 15 with FacebookException

use of com.facebook.FacebookException in project facebook-android-sdk by facebook.

the class GraphUtil method createOpenGraphObjectForPost.

/**
     * Creates a JSONObject for an open graph object that is suitable for posting.
     * @param type the Open Graph object type for the object, or null if it will be specified later
     * @param title the title of the object, or null if it will be specified later
     * @param imageUrl the URL of an image associated with the object, or null
     * @param url the URL associated with the object, or null
     * @param description the description of the object, or null
     * @param objectProperties the properties of the open graph object
     * @param id the id of the object if the post is for update
     * @return a JSONObject
     */
public static JSONObject createOpenGraphObjectForPost(String type, String title, String imageUrl, String url, String description, JSONObject objectProperties, String id) {
    JSONObject openGraphObject = new JSONObject();
    try {
        if (type != null) {
            openGraphObject.put("type", type);
        }
        openGraphObject.put("title", title);
        if (imageUrl != null) {
            JSONObject imageUrlObject = new JSONObject();
            imageUrlObject.put("url", imageUrl);
            JSONArray imageUrls = new JSONArray();
            imageUrls.put(imageUrlObject);
            openGraphObject.put("image", imageUrls);
        }
        openGraphObject.put("url", url);
        openGraphObject.put("description", description);
        openGraphObject.put(NativeProtocol.OPEN_GRAPH_CREATE_OBJECT_KEY, true);
        if (objectProperties != null) {
            openGraphObject.put("data", objectProperties);
        }
        if (id != null) {
            openGraphObject.put("id", id);
        }
    } catch (JSONException e) {
        throw new FacebookException("An error occurred while setting up the graph object", e);
    }
    return openGraphObject;
}
Also used : JSONObject(org.json.JSONObject) FacebookException(com.facebook.FacebookException) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Aggregations

FacebookException (com.facebook.FacebookException)70 Bundle (android.os.Bundle)24 JSONObject (org.json.JSONObject)24 JSONException (org.json.JSONException)19 Bitmap (android.graphics.Bitmap)13 GraphRequest (com.facebook.GraphRequest)10 JSONArray (org.json.JSONArray)10 Intent (android.content.Intent)9 Uri (android.net.Uri)8 GraphResponse (com.facebook.GraphResponse)8 URISyntaxException (java.net.URISyntaxException)8 AccessToken (com.facebook.AccessToken)7 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)5 FacebookRequestError (com.facebook.FacebookRequestError)5 LoginResult (com.facebook.login.LoginResult)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 InputStreamReader (java.io.InputStreamReader)5 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5