in facebook-share/src/main/java/com/facebook/share/ShareApi.java [325:397]
private void sharePhotoContent(
final SharePhotoContent photoContent, final FacebookCallback<Sharer.Result> callback) {
final Mutable<Integer> requestCount = new Mutable<Integer>(0);
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>();
final ArrayList<JSONObject> results = new ArrayList<JSONObject>();
final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>();
final GraphRequest.Callback requestCallback =
new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject result = response.getJSONObject();
if (result != null) {
results.add(result);
}
if (response.getError() != null) {
errorResponses.add(response);
}
requestCount.value -= 1;
if (requestCount.value == 0) {
if (!errorResponses.isEmpty()) {
ShareInternalUtility.invokeCallbackWithResults(
callback, null, errorResponses.get(0));
} else if (!results.isEmpty()) {
final String postId = results.get(0).optString("id");
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
}
}
};
try {
for (SharePhoto photo : photoContent.getPhotos()) {
Bundle params;
try {
params = getSharePhotoCommonParameters(photo, photoContent);
} catch (JSONException e) {
ShareInternalUtility.invokeCallbackWithException(callback, e);
return;
}
final Bitmap bitmap = photo.getBitmap();
final Uri photoUri = photo.getImageUrl();
String caption = photo.getCaption();
if (caption == null) {
caption = this.getMessage();
}
if (bitmap != null) {
requests.add(
GraphRequest.newUploadPhotoRequest(
accessToken,
getGraphPath(PHOTOS_EDGE),
bitmap,
caption,
params,
requestCallback));
} else if (photoUri != null) {
requests.add(
GraphRequest.newUploadPhotoRequest(
accessToken,
getGraphPath(PHOTOS_EDGE),
photoUri,
caption,
params,
requestCallback));
}
}
requestCount.value += requests.size();
for (GraphRequest request : requests) {
request.executeAsync();
}
} catch (final FileNotFoundException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}