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);
}
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);
}
}
}
}
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());
}
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);
}
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);
}
}
Aggregations