Search in sources :

Example 1 with ShareOpenGraphObject

use of com.facebook.share.model.ShareOpenGraphObject 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 ShareOpenGraphObject

use of com.facebook.share.model.ShareOpenGraphObject 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 ShareOpenGraphObject

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

the class RequestTests method testShareOpenGraphContent.

@LargeTest
public void testShareOpenGraphContent() 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).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);
    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) {
                    notifyShareFinished();
                }

                private void notifyShareFinished() {
                    synchronized (shareApi) {
                        shareApi.notifyAll();
                    }
                }
            });
        }
    });
    synchronized (shareApi) {
        shareApi.wait(REQUEST_TIMEOUT_MILLIS);
    }
    assertNotNull(actionId.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) Sharer(com.facebook.share.Sharer) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 4 with ShareOpenGraphObject

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

the class RequestTests method testCreateOpenGraphObjectWithBadImageType.

@LargeTest
public void testCreateOpenGraphObjectWithBadImageType() throws InterruptedException {
    // only image urls are accepted for createOpenGraphObject
    Bitmap image = createTestBitmap(128);
    SharePhoto photo = new SharePhoto.Builder().setBitmap(image).setUserGenerated(true).build();
    ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").putPhoto("og:image", photo).build();
    try {
        GraphRequest request = ShareGraphRequest.createOpenGraphObject(ogObject);
        request.executeAndWait();
        // should fail because do not accept images without image_url
        fail();
    } catch (Exception e) {
        if (!(e instanceof FacebookException && e.getMessage().equals("Unable to attach images"))) {
            fail();
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) SharePhoto(com.facebook.share.model.SharePhoto) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) IOException(java.io.IOException) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 5 with ShareOpenGraphObject

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

the class RequestTests method testCreateOpenGraphObject.

@LargeTest
public void testCreateOpenGraphObject() throws InterruptedException {
    Uri testImage = Uri.parse("http://i.imgur.com/Diyvl7q.jpg");
    SharePhoto photo = new SharePhoto.Builder().setImageUrl(testImage).setUserGenerated(true).build();
    ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").putPhoto("og:image", photo).build();
    try {
        GraphRequest request = ShareGraphRequest.createOpenGraphObject(ogObject);
        GraphResponse response = request.executeAndWait();
        assertNotNull(response);
        assertNull(response.getError());
        JSONObject graphResult = response.getJSONObject();
        assertNotNull(graphResult);
        assertNotNull(graphResult.optString("id"));
        assertNotNull(response.getRawResponse());
    } catch (Exception e) {
        fail();
    }
}
Also used : JSONObject(org.json.JSONObject) SharePhoto(com.facebook.share.model.SharePhoto) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) Uri(android.net.Uri) URISyntaxException(java.net.URISyntaxException) JSONException(org.json.JSONException) IOException(java.io.IOException) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)7 LargeTest (android.test.suitebuilder.annotation.LargeTest)4 ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)4 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)4 Sharer (com.facebook.share.Sharer)3 SharePhoto (com.facebook.share.model.SharePhoto)3 Bitmap (android.graphics.Bitmap)2 ShareApi (com.facebook.share.ShareApi)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 JSONException (org.json.JSONException)2 Uri (android.net.Uri)1 FacebookException (com.facebook.FacebookException)1 LoginResult (com.facebook.login.LoginResult)1 ReadableMap (com.facebook.react.bridge.ReadableMap)1 ReadableMapKeySetIterator (com.facebook.react.bridge.ReadableMapKeySetIterator)1 ShareLinkContent (com.facebook.share.model.ShareLinkContent)1 Photo (com.kickstarter.models.Photo)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1