com.facebook.share.model.SharePhoto Java Examples

The following examples show how to use com.facebook.share.model.SharePhoto. 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: ShareContentValidation.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private static void validatePhotoContent(
        SharePhotoContent photoContent, Validator validator) {
    List<SharePhoto> photos = photoContent.getPhotos();
    if (photos == null || photos.isEmpty()) {
        throw new FacebookException("Must specify at least one Photo in SharePhotoContent.");
    }
    if (photos.size() > ShareConstants.MAXIMUM_PHOTO_COUNT) {
        throw new FacebookException(
                String.format(
                        Locale.ROOT,
                        "Cannot add more than %d photos.",
                        ShareConstants.MAXIMUM_PHOTO_COUNT));
    }

    for (SharePhoto photo : photos) {
        validator.validate(photo);
    }
}
 
Example #2
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private static void validatePhotoForApi(SharePhoto photo, Validator validator) {
    if (photo == null) {
        throw new FacebookException("Cannot share a null SharePhoto");
    }

    Bitmap photoBitmap = photo.getBitmap();
    Uri photoUri = photo.getImageUrl();

    if (photoBitmap == null) {
        if (photoUri == null) {
            throw new FacebookException(
                    "SharePhoto does not have a Bitmap or ImageUrl specified");
        }

        if (Utility.isWebUri(photoUri) && !validator.isOpenGraphContent()) {
            throw new FacebookException(
                    "Cannot set the ImageUrl of a SharePhoto to the Uri of an image on the " +
                            "web when sharing SharePhotoContent");
        }
    }
}
 
Example #3
Source File: ShareInternalUtility.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
public static JSONObject toJSONObjectForWeb(
        final ShareOpenGraphContent shareOpenGraphContent)
        throws JSONException {
    ShareOpenGraphAction action = shareOpenGraphContent.getAction();

    return OpenGraphJSONUtility.toJSONObject(
            action,
            new OpenGraphJSONUtility.PhotoJSONProcessor() {
                @Override
                public JSONObject toJSONObject(SharePhoto photo) {
                    Uri photoUri = photo.getImageUrl();
                    JSONObject photoJSONObject = new JSONObject();
                    try {
                        photoJSONObject.put(
                                NativeProtocol.IMAGE_URL_KEY, photoUri.toString());
                    } catch (JSONException e) {
                        throw new FacebookException("Unable to attach images", e);
                    }
                    return photoJSONObject;
                }
            });
}
 
Example #4
Source File: ShareInternalUtility.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
private static NativeAppCallAttachmentStore.Attachment getAttachment(
        UUID callId,
        SharePhoto photo) {
    Bitmap bitmap = photo.getBitmap();
    Uri photoUri = photo.getImageUrl();
    NativeAppCallAttachmentStore.Attachment attachment = null;
    if (bitmap != null) {
        attachment = NativeAppCallAttachmentStore.createAttachment(
                callId,
                bitmap);
    } else if (photoUri != null) {
        attachment = NativeAppCallAttachmentStore.createAttachment(
                callId,
                photoUri);
    }

    return attachment;
}
 
Example #5
Source File: SocialSharePlugin.java    From social_share_plugin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void facebookShare(String caption, String mediaPath) {
    final File media = new File(mediaPath);
    final Uri uri = FileProvider.getUriForFile(activity, activity.getPackageName() + ".social.share.fileprovider",
            media);
    final SharePhoto photo = new SharePhoto.Builder().setImageUrl(uri).setCaption(caption).build();
    final SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
    final ShareDialog shareDialog = new ShareDialog(activity);
    shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {
            channel.invokeMethod("onSuccess", null);
            Log.d("SocialSharePlugin", "Sharing successfully done.");
        }

        @Override
        public void onCancel() {
            channel.invokeMethod("onCancel", null);
            Log.d("SocialSharePlugin", "Sharing cancelled.");
        }

        @Override
        public void onError(FacebookException error) {
            channel.invokeMethod("onError", error.getMessage());
            Log.d("SocialSharePlugin", "Sharing error occurred.");
        }
    });

    if (ShareDialog.canShow(SharePhotoContent.class)) {
        shareDialog.show(content);
    }
}
 
Example #6
Source File: OpenGraphJSONUtility.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static Object toJSONValue(
        @Nullable final Object object,
        final PhotoJSONProcessor photoJSONProcessor) throws JSONException {
    if (object == null) {
        return JSONObject.NULL;
    }
    if ((object instanceof String) ||
            (object instanceof Boolean) ||
            (object instanceof Double) ||
            (object instanceof Float) ||
            (object instanceof Integer) ||
            (object instanceof Long)) {
        return object;
    }
    if (object instanceof SharePhoto) {
        if (photoJSONProcessor != null) {
            return photoJSONProcessor.toJSONObject((SharePhoto) object);
        }
        return null;
    }
    if (object instanceof ShareOpenGraphObject) {
        return toJSONObject((ShareOpenGraphObject) object, photoJSONProcessor);
    }
    if (object instanceof List) {
        return toJSONArray((List) object, photoJSONProcessor);
    }
    throw new IllegalArgumentException(
            "Invalid object found for JSON serialization: " +object.toString());
}
 
Example #7
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static void validatePhotoForNativeDialog(SharePhoto photo, Validator validator) {
    validatePhotoForApi(photo, validator);

    if (photo.getBitmap() != null || !Utility.isWebUri(photo.getImageUrl())) {
        Validate.hasContentProvider(FacebookSdk.getApplicationContext());
    }
}
 
Example #8
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static void validatePhotoForWebDialog(SharePhoto photo, Validator validator) {
    if (photo == null) {
        throw new FacebookException("Cannot share a null SharePhoto");
    }

    Uri imageUri = photo.getImageUrl();
    if (imageUri == null || !Utility.isWebUri(imageUri)) {
        throw new FacebookException(
                "SharePhoto must have a non-null imageUrl set to the Uri of an image " +
                        "on the web");
    }
}
 
Example #9
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static void validateVideoContent(
        ShareVideoContent videoContent, Validator validator) {
    validator.validate(videoContent.getVideo());

    SharePhoto previewPhoto = videoContent.getPreviewPhoto();
    if (previewPhoto != null) {
        validator.validate(previewPhoto);
    }
}
 
Example #10
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static void validateOpenGraphValueContainerObject(
        Object o, Validator validator) {
    if (o instanceof ShareOpenGraphObject) {
        validator.validate((ShareOpenGraphObject) o);
    } else if (o instanceof SharePhoto) {
        validator.validate((SharePhoto) o);
    }
}
 
Example #11
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@Override
public void validate(final SharePhoto photo) {
    validatePhotoForWebDialog(photo, this);
}
 
Example #12
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@Override
public void validate(final SharePhoto photo) {
    validatePhotoForApi(photo, this);
}
 
Example #13
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
public void validate(final SharePhoto photo) {
    validatePhotoForNativeDialog(photo, this);
}
 
Example #14
Source File: ShareInternalUtility.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
public static JSONObject toJSONObjectForCall(
        final UUID callId,
        final ShareOpenGraphContent content)
        throws JSONException {
    final ShareOpenGraphAction action = content.getAction();
    final ArrayList<NativeAppCallAttachmentStore.Attachment> attachments = new ArrayList<>();
    JSONObject actionJSON = OpenGraphJSONUtility.toJSONObject(
            action,
            new OpenGraphJSONUtility.PhotoJSONProcessor() {
                @Override
                public JSONObject toJSONObject(SharePhoto photo) {
                    NativeAppCallAttachmentStore.Attachment attachment = getAttachment(
                            callId,
                            photo);

                    if (attachment == null) {
                        return null;
                    }

                    attachments.add(attachment);

                    JSONObject photoJSONObject = new JSONObject();
                    try {
                        photoJSONObject.put(
                                NativeProtocol.IMAGE_URL_KEY, attachment.getAttachmentUrl());
                        if (photo.getUserGenerated()) {
                            photoJSONObject.put(NativeProtocol.IMAGE_USER_GENERATED_KEY, true);
                        }
                    } catch (JSONException e) {
                        throw new FacebookException("Unable to attach images", e);
                    }
                    return photoJSONObject;
                }
            });

    NativeAppCallAttachmentStore.addAttachments(attachments);
    // People and place tags must be moved from the share content to the open graph action
    if (content.getPlaceId() != null) {
        String placeTag = actionJSON.optString("place");

        // Only if the place tag is already empty or null replace with the id from the
        // share content
        if (Utility.isNullOrEmpty(placeTag)) {
            actionJSON.put("place", content.getPlaceId());
        }
    }

    if (content.getPeopleIds() != null) {
        JSONArray peopleTags = actionJSON.optJSONArray("tags");
        Set<String> peopleIdSet = peopleTags == null
                ? new HashSet<String>()
                : Utility.jsonArrayToSet(peopleTags);

        for (String peopleId : content.getPeopleIds()) {
            peopleIdSet.add(peopleId);
        }
        actionJSON.put("tags", new ArrayList<>(peopleIdSet));
    }

    return actionJSON;
}
 
Example #15
Source File: OpenGraphJSONUtility.java    From kognitivo with Apache License 2.0 votes vote down vote up
public JSONObject toJSONObject(SharePhoto photo);