Search in sources :

Example 1 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project android-oss by kickstarter.

the class ThanksActivity method startShareOnFacebook.

private void startShareOnFacebook(@NonNull final Project project) {
    if (!ShareDialog.canShow(ShareLinkContent.class)) {
        return;
    }
    final Photo photo = project.photo();
    final ShareOpenGraphObject object = new ShareOpenGraphObject.Builder().putString("og:type", "kickstarter:project").putString("og:title", project.name()).putString("og:description", project.blurb()).putString("og:image", photo == null ? null : photo.small()).putString("og:url", project.webProjectUrl()).build();
    final ShareOpenGraphAction action = new ShareOpenGraphAction.Builder().setActionType("kickstarter:back").putObject("project", object).build();
    final ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setPreviewPropertyName("project").setAction(action).build();
    shareDialog.show(content);
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) Photo(com.kickstarter.models.Photo) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Example 2 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class RequestTests method testShareOpenGraphContentWithBadType.

@LargeTest
public void testShareOpenGraphContentWithBadType() throws Exception {
    ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").build();
    ShareOpenGraphAction ogAction = new ShareOpenGraphAction.Builder().setActionType(TEST_OG_ACTION_TYPE + "bad").putObject("test", ogObject).build();
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(ogAction).setPreviewPropertyName("test").build();
    final ShareApi shareApi = new ShareApi(content);
    final AtomicReference<String> actionId = new AtomicReference<>(null);
    final AtomicBoolean errorOccurred = new AtomicBoolean(false);
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            shareApi.share(new FacebookCallback<Sharer.Result>() {

                @Override
                public void onSuccess(Sharer.Result result) {
                    actionId.set(result.getPostId());
                    notifyShareFinished();
                }

                @Override
                public void onCancel() {
                    notifyShareFinished();
                }

                @Override
                public void onError(FacebookException error) {
                    errorOccurred.set(true);
                    notifyShareFinished();
                }

                private void notifyShareFinished() {
                    synchronized (shareApi) {
                        shareApi.notifyAll();
                    }
                }
            });
        }
    });
    synchronized (shareApi) {
        shareApi.wait(REQUEST_TIMEOUT_MILLIS);
    }
    assertNull(actionId.get());
    assertTrue(errorOccurred.get());
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) AtomicReference(java.util.concurrent.atomic.AtomicReference) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Sharer(com.facebook.share.Sharer) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 3 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class ShareInternalUtilityTest method testJsonSerializationOfOpenGraphExistingPlace.

@Test
public void testJsonSerializationOfOpenGraphExistingPlace() {
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(new ShareOpenGraphAction.Builder().putString("place", "1").build()).setPlaceId("2").build();
    try {
        JSONObject object = ShareInternalUtility.toJSONObjectForCall(null, content);
        assertEquals("1", object.getString("place"));
    } catch (JSONException ex) {
        // Fail
        assertNotNull(ex);
        return;
    }
}
Also used : JSONObject(org.json.JSONObject) ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) JSONException(org.json.JSONException) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test)

Example 4 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class LegacyNativeDialogParameters method create.

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;
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) SharePhotoContent(com.facebook.share.model.SharePhotoContent) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) ShareVideoContent(com.facebook.share.model.ShareVideoContent) JSONException(org.json.JSONException) ArrayList(java.util.ArrayList) List(java.util.List) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Example 5 with ShareOpenGraphContent

use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.

the class NativeDialogParameters method create.

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());
        }
    } else if (shareContent instanceof ShareMediaContent) {
        final ShareMediaContent mediaContent = (ShareMediaContent) shareContent;
        List<Bundle> mediaInfos = ShareInternalUtility.getMediaInfos(mediaContent, callId);
        nativeParams = create(mediaContent, mediaInfos, shouldFailOnDataError);
    } else if (shareContent instanceof ShareCameraEffectContent) {
        final ShareCameraEffectContent cameraEffectContent = (ShareCameraEffectContent) shareContent;
        // Put Bitmaps behind content uris.
        Bundle attachmentUrlsBundle = ShareInternalUtility.getTextureUrlBundle(cameraEffectContent, callId);
        nativeParams = create(cameraEffectContent, attachmentUrlsBundle, shouldFailOnDataError);
    } else if (shareContent instanceof ShareMessengerGenericTemplateContent) {
        final ShareMessengerGenericTemplateContent genericTemplateContent = (ShareMessengerGenericTemplateContent) shareContent;
        nativeParams = create(genericTemplateContent, shouldFailOnDataError);
    } else if (shareContent instanceof ShareMessengerOpenGraphMusicTemplateContent) {
        final ShareMessengerOpenGraphMusicTemplateContent openGraphMusicTemplateContent = (ShareMessengerOpenGraphMusicTemplateContent) shareContent;
        nativeParams = create(openGraphMusicTemplateContent, shouldFailOnDataError);
    } else if (shareContent instanceof ShareMessengerMediaTemplateContent) {
        final ShareMessengerMediaTemplateContent mediaTemplateContent = (ShareMessengerMediaTemplateContent) shareContent;
        nativeParams = create(mediaTemplateContent, shouldFailOnDataError);
    }
    return nativeParams;
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) SharePhotoContent(com.facebook.share.model.SharePhotoContent) ShareCameraEffectContent(com.facebook.share.model.ShareCameraEffectContent) Bundle(android.os.Bundle) ShareMessengerMediaTemplateContent(com.facebook.share.model.ShareMessengerMediaTemplateContent) JSONException(org.json.JSONException) ShareMessengerGenericTemplateContent(com.facebook.share.model.ShareMessengerGenericTemplateContent) ShareMediaContent(com.facebook.share.model.ShareMediaContent) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) JSONObject(org.json.JSONObject) FacebookException(com.facebook.FacebookException) ShareVideoContent(com.facebook.share.model.ShareVideoContent) ShareMessengerOpenGraphMusicTemplateContent(com.facebook.share.model.ShareMessengerOpenGraphMusicTemplateContent) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)14 ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)9 Test (org.junit.Test)6 FacebookException (com.facebook.FacebookException)4 ShareLinkContent (com.facebook.share.model.ShareLinkContent)4 ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Sharer (com.facebook.share.Sharer)3 ArrayList (java.util.ArrayList)3 Bundle (android.os.Bundle)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 ShareApi (com.facebook.share.ShareApi)2 SharePhoto (com.facebook.share.model.SharePhoto)2 SharePhotoContent (com.facebook.share.model.SharePhotoContent)2 ShareVideoContent (com.facebook.share.model.ShareVideoContent)2 List (java.util.List)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Intent (android.content.Intent)1