Search in sources :

Example 1 with ShareOpenGraphAction

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

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

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

the class ShareInternalUtility method toJSONObjectForCall.

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");
        // 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 JSONArray(peopleIdSet));
    }
    return actionJSON;
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) SharePhoto(com.facebook.share.model.SharePhoto) FacebookException(com.facebook.FacebookException)

Example 4 with ShareOpenGraphAction

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

the class RpsFragment method getThrowAction.

private ShareOpenGraphAction getThrowAction() {
    // The OG objects have their own bitmaps we could rely on, but in order to demonstrate
    // attaching an in-memory bitmap (e.g., a game screencap) we'll send the bitmap explicitly
    // ourselves.
    ImageButton view = gestureImages[playerChoice];
    BitmapDrawable drawable = (BitmapDrawable) view.getBackground();
    final Bitmap bitmap = drawable.getBitmap();
    return new ShareOpenGraphAction.Builder().setActionType(OpenGraphConsts.THROW_ACTION_TYPE).putString("fb_sample_rps:gesture", getBuiltInGesture(playerChoice)).putString("fb_sample_rps:opposing_gesture", getBuiltInGesture(computerChoice)).putPhotoArrayList("og:image", new ArrayList<SharePhoto>() {

        {
            add(new SharePhoto.Builder().setBitmap(bitmap).build());
        }
    }).build();
}
Also used : Bitmap(android.graphics.Bitmap) SharePhoto(com.facebook.share.model.SharePhoto) ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ArrayList(java.util.ArrayList) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 5 with ShareOpenGraphAction

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

the class RpsFragment method publishResult.

private void publishResult() {
    if (shouldImplicitlyPublish && canPublish()) {
        String photoUri = PHOTO_URIS[playerChoice];
        SharePhoto.Builder sharePhotoBuilder = new SharePhoto.Builder();
        if (photoUri == null) {
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), DRAWABLES_HUMAN[playerChoice]);
            sharePhotoBuilder.setBitmap(bitmap);
        } else {
            sharePhotoBuilder.setImageUrl(Uri.parse(photoUri));
        }
        sharePhotoBuilder.setUserGenerated(false);
        final SharePhoto gesturePhoto = sharePhotoBuilder.build();
        ShareOpenGraphObject gameObject = createGameObject(gesturePhoto);
        ShareOpenGraphAction playAction = createPlayActionWithGame(gameObject);
        ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(playAction).setPreviewPropertyName("game").build();
        ShareApi.share(content, new FacebookCallback<Sharer.Result>() {

            @Override
            public void onSuccess(Sharer.Result result) {
                Log.i(TAG, "Posted OG Action with id: " + result.getPostId());
            }

            @Override
            public void onCancel() {
            // This should not happen
            }

            @Override
            public void onError(FacebookException error) {
                Log.e(TAG, "Play action creation failed: " + error.getMessage());
            }
        });
    }
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphObject(com.facebook.share.model.ShareOpenGraphObject) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) LoginResult(com.facebook.login.LoginResult) Bitmap(android.graphics.Bitmap) SharePhoto(com.facebook.share.model.SharePhoto) Sharer(com.facebook.share.Sharer)

Aggregations

ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)10 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)7 ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)4 Sharer (com.facebook.share.Sharer)3 SharePhoto (com.facebook.share.model.SharePhoto)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Bitmap (android.graphics.Bitmap)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 ShareApi (com.facebook.share.ShareApi)2 ArrayList (java.util.ArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)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