com.facebook.share.model.SharePhotoContent Java Examples

The following examples show how to use com.facebook.share.model.SharePhotoContent. 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 validate(ShareContent content, Validator validator)
        throws FacebookException {
    if (content == null) {
        throw new FacebookException("Must provide non-null content to share");
    }

    if (content instanceof ShareLinkContent) {
        validator.validate((ShareLinkContent) content);
    } else if (content instanceof SharePhotoContent) {
        validator.validate((SharePhotoContent) content);
    } else if (content instanceof ShareVideoContent) {
        validator.validate((ShareVideoContent) content);
    } else if (content instanceof ShareOpenGraphContent) {
        validator.validate((ShareOpenGraphContent) content);
    }
}
 
Example #2
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 #3
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 #4
Source File: NativeDialogParameters.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static Bundle create(
        UUID callId,
        ShareContent shareContent,
        boolean shouldFailOnDataError) {
    Validate.notNull(shareContent, "shareContent");
    Validate.notNull(callId, "callId");

    Bundle nativeParams = null;
    if (shareContent instanceof ShareLinkContent) {
        final ShareLinkContent linkContent = (ShareLinkContent) shareContent;
        nativeParams = create(linkContent, shouldFailOnDataError);
    } else if (shareContent instanceof SharePhotoContent) {
        final SharePhotoContent photoContent = (SharePhotoContent) shareContent;
        List<String> photoUrls = ShareInternalUtility.getPhotoUrls(
                photoContent,
                callId);

        nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
    } else if (shareContent instanceof ShareVideoContent) {
        final ShareVideoContent videoContent = (ShareVideoContent) shareContent;
        String videoUrl = ShareInternalUtility.getVideoUrl(videoContent, callId);

        nativeParams = create(videoContent, videoUrl, shouldFailOnDataError);
    } else if (shareContent instanceof ShareOpenGraphContent) {
        final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
        try {
            JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(
                    callId, openGraphContent);
            openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(
                    openGraphActionJSON, false);
            nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
        } catch (final JSONException e) {
            throw new FacebookException(
                    "Unable to create a JSON Object from the provided ShareOpenGraphContent: "
                            + e.getMessage());
        }
    }

    return nativeParams;
}
 
Example #5
Source File: NativeDialogParameters.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static Bundle create(
        SharePhotoContent photoContent,
        List<String> imageUrls,
        boolean dataErrorsFatal) {
    Bundle params = createBaseParameters(photoContent, dataErrorsFatal);

    params.putStringArrayList(ShareConstants.PHOTOS, new ArrayList<>(imageUrls));

    return params;
}
 
Example #6
Source File: LegacyNativeDialogParameters.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static Bundle create(
        UUID callId,
        ShareContent shareContent,
        boolean shouldFailOnDataError) {
    Validate.notNull(shareContent, "shareContent");
    Validate.notNull(callId, "callId");

    Bundle nativeParams = null;
    if (shareContent instanceof ShareLinkContent) {
        final ShareLinkContent linkContent = (ShareLinkContent)shareContent;
        nativeParams = create(linkContent, shouldFailOnDataError);
    } else if (shareContent instanceof SharePhotoContent) {
        final SharePhotoContent photoContent = (SharePhotoContent)shareContent;
        List<String> photoUrls = ShareInternalUtility.getPhotoUrls(
                photoContent,
                callId);

        nativeParams = create(photoContent, photoUrls, shouldFailOnDataError);
    } else if (shareContent instanceof ShareVideoContent) {
        final ShareVideoContent videoContent = (ShareVideoContent)shareContent;
        nativeParams = create(videoContent, shouldFailOnDataError);
    } else if (shareContent instanceof ShareOpenGraphContent) {
        final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent;
        try {
            JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall(
                    callId, openGraphContent);

            nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError);
        } catch (final JSONException e) {
            throw new FacebookException(
                    "Unable to create a JSON Object from the provided ShareOpenGraphContent: "
                            + e.getMessage());
        }
    }

    return nativeParams;
}
 
Example #7
Source File: LegacyNativeDialogParameters.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
private static Bundle create(
        SharePhotoContent photoContent,
        List<String> imageUrls,
        boolean dataErrorsFatal) {
    Bundle params = createBaseParameters(photoContent, dataErrorsFatal);

    params.putStringArrayList(ShareConstants.LEGACY_PHOTOS, new ArrayList<>(imageUrls));

    return params;
}
 
Example #8
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
@Override
public void validate(final SharePhotoContent photoContent) {
    throw new FacebookException("Cannot share SharePhotoContent via web sharing dialogs");
}
 
Example #9
Source File: ShareContentValidation.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
public void validate(final SharePhotoContent photoContent) {
    validatePhotoContent(photoContent, this);
}