Search in sources :

Example 46 with FacebookException

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

the class ShareApi method stageOpenGraphAction.

private void stageOpenGraphAction(final Bundle parameters, final CollectionMapper.OnMapperCompleteListener onOpenGraphActionStagedListener) {
    final CollectionMapper.Collection<String> collection = new CollectionMapper.Collection<String>() {

        @Override
        public Iterator<String> keyIterator() {
            return parameters.keySet().iterator();
        }

        @Override
        public Object get(String key) {
            return parameters.get(key);
        }

        @Override
        public void set(String key, Object value, CollectionMapper.OnErrorListener onErrorListener) {
            if (!Utility.putJSONValueInBundle(parameters, key, value)) {
                onErrorListener.onError(new FacebookException("Unexpected value: " + value.toString()));
            }
        }
    };
    stageCollectionValues(collection, onOpenGraphActionStagedListener);
}
Also used : FacebookException(com.facebook.FacebookException) CollectionMapper(com.facebook.internal.CollectionMapper) JSONObject(org.json.JSONObject)

Example 47 with FacebookException

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

the class ProfilePictureView method processResponse.

private void processResponse(ImageResponse response) {
    // 2. Detached this view, in which case the response should be discarded.
    if (response.getRequest() == lastRequest) {
        lastRequest = null;
        Bitmap responseImage = response.getBitmap();
        Exception error = response.getError();
        if (error != null) {
            OnErrorListener listener = onErrorListener;
            if (listener != null) {
                listener.onError(new FacebookException("Error in downloading profile picture for profileId: " + getProfileId(), error));
            } else {
                Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, error.toString());
            }
        } else if (responseImage != null) {
            setImageBitmap(responseImage);
            if (response.isCachedRedirect()) {
                sendImageRequest(false);
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) FacebookException(com.facebook.FacebookException) FacebookException(com.facebook.FacebookException)

Example 48 with FacebookException

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

the class DeviceShareDialog method showImpl.

@Override
protected void showImpl(final ShareContent content, final Object mode) {
    if (content == null) {
        throw new FacebookException("Must provide non-null content to share");
    }
    if (!(content instanceof ShareLinkContent) && !(content instanceof ShareOpenGraphContent)) {
        throw new FacebookException(this.getClass().getSimpleName() + " only supports ShareLinkContent or ShareOpenGraphContent");
    }
    Intent intent = new Intent();
    intent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class);
    intent.setAction(DeviceShareDialogFragment.TAG);
    intent.putExtra("content", content);
    startActivityForResult(intent, getRequestCode());
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) FacebookException(com.facebook.FacebookException) Intent(android.content.Intent) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Example 49 with FacebookException

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

the class ShareApi method shareOpenGraphContent.

private void shareOpenGraphContent(final ShareOpenGraphContent openGraphContent, final FacebookCallback<Sharer.Result> callback) {
    // In order to create a new Open Graph action using a custom object that does not already
    // exist (objectID or URL), you must first send a request to post the object and then
    // another to post the action.  If a local image is supplied with the object or action, that
    // must be staged first and then referenced by the staging URL that is returned by that
    // request.
    final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {

        @Override
        public void onCompleted(GraphResponse response) {
            final JSONObject data = response.getJSONObject();
            final String postId = (data == null ? null : data.optString("id"));
            ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
        }
    };
    final ShareOpenGraphAction action = openGraphContent.getAction();
    final Bundle parameters = action.getBundle();
    this.addCommonParameters(parameters, openGraphContent);
    if (!Utility.isNullOrEmpty(this.getMessage())) {
        parameters.putString("message", this.getMessage());
    }
    final CollectionMapper.OnMapperCompleteListener stageCallback = new CollectionMapper.OnMapperCompleteListener() {

        @Override
        public void onComplete() {
            try {
                handleImagesOnAction(parameters);
                new GraphRequest(AccessToken.getCurrentAccessToken(), getGraphPath(URLEncoder.encode(action.getActionType(), DEFAULT_CHARSET)), parameters, HttpMethod.POST, requestCallback).executeAsync();
            } catch (final UnsupportedEncodingException ex) {
                ShareInternalUtility.invokeCallbackWithException(callback, ex);
            }
        }

        @Override
        public void onError(FacebookException exception) {
            ShareInternalUtility.invokeCallbackWithException(callback, exception);
        }
    };
    this.stageOpenGraphAction(parameters, stageCallback);
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FacebookCallback(com.facebook.FacebookCallback) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) FacebookException(com.facebook.FacebookException) CollectionMapper(com.facebook.internal.CollectionMapper)

Example 50 with FacebookException

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

the class NativeAppLoginMethodHandler method handleResultOk.

private LoginClient.Result handleResultOk(LoginClient.Request request, Intent data) {
    Bundle extras = data.getExtras();
    String error = getError(extras);
    String errorCode = extras.getString("error_code");
    String errorMessage = getErrorMessage(extras);
    String e2e = extras.getString(NativeProtocol.FACEBOOK_PROXY_AUTH_E2E_KEY);
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }
    if (error == null && errorCode == null && errorMessage == null) {
        try {
            AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), extras, AccessTokenSource.FACEBOOK_APPLICATION_WEB, request.getApplicationId());
            return LoginClient.Result.createTokenResult(request, token);
        } catch (FacebookException ex) {
            return LoginClient.Result.createErrorResult(request, null, ex.getMessage());
        }
    } else if (ServerProtocol.errorsProxyAuthDisabled.contains(error)) {
        return null;
    } else if (ServerProtocol.errorsUserCanceled.contains(error)) {
        return LoginClient.Result.createCancelResult(request, null);
    } else {
        return LoginClient.Result.createErrorResult(request, error, errorMessage, errorCode);
    }
}
Also used : Bundle(android.os.Bundle) AccessToken(com.facebook.AccessToken) FacebookException(com.facebook.FacebookException)

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