Search in sources :

Example 6 with ShareOpenGraphContent

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

the class ShareContentValidationTest method testItValidatesShareOpenGraphWithNoActionByMessage.

// -ShareOpenGraphContent
@Test(expected = FacebookException.class)
public void testItValidatesShareOpenGraphWithNoActionByMessage() {
    ShareOpenGraphContent shareOpenGraphContent = new ShareOpenGraphContent.Builder().setAction(null).build();
    ShareContentValidation.validateForMessage(shareOpenGraphContent);
}
Also used : ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with ShareOpenGraphContent

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

the class DeviceShareDialog method showImpl.

@Override
protected void showImpl(final ShareContent content, final Object mode) {
    if (content == null) {
        throw new FacebookException("Must provide non-null content to share");
    }
    if (!(content instanceof ShareLinkContent) && !(content instanceof ShareOpenGraphContent)) {
        throw new FacebookException(this.getClass().getSimpleName() + " only supports ShareLinkContent or ShareOpenGraphContent");
    }
    Intent intent = new Intent();
    intent.setClass(FacebookSdk.getApplicationContext(), FacebookActivity.class);
    intent.setAction(DeviceShareDialogFragment.TAG);
    intent.putExtra("content", content);
    startActivityForResult(intent, getRequestCode());
}
Also used : ShareLinkContent(com.facebook.share.model.ShareLinkContent) FacebookException(com.facebook.FacebookException) Intent(android.content.Intent) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Example 8 with ShareOpenGraphContent

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

Example 9 with ShareOpenGraphContent

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

the class SelectionFragment method createOpenGraphContent.

private ShareOpenGraphContent createOpenGraphContent() {
    ShareOpenGraphAction.Builder actionBuilder = createEatActionBuilder();
    boolean userGenerated = false;
    if (photoUri != null) {
        String photoUriString = photoUri.toString();
        Pair<File, Integer> fileAndMinDimension = getImageFileAndMinDimension();
        userGenerated = fileAndMinDimension.second >= USER_GENERATED_MIN_SIZE;
        if (fileAndMinDimension != null) {
            final SharePhoto actionPhoto = new SharePhoto.Builder().setImageUrl(Uri.parse(photoUriString)).setUserGenerated(userGenerated).build();
            actionBuilder.putPhotoArrayList("image", new ArrayList<SharePhoto>() {

                {
                    add(actionPhoto);
                }
            });
        }
    }
    return new ShareOpenGraphContent.Builder().setAction(actionBuilder.build()).setPreviewPropertyName("meal").build();
}
Also used : SharePhoto(com.facebook.share.model.SharePhoto) ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent)

Example 10 with ShareOpenGraphContent

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

the class ShareContentValidationTest method testItValidatesShareOpenGraphWithPreviewPropertyNameByMessage.

@Test(expected = FacebookException.class)
public void testItValidatesShareOpenGraphWithPreviewPropertyNameByMessage() {
    ShareOpenGraphAction shareOpenGraphAction = new ShareOpenGraphAction.Builder().setActionType("foo").build();
    ShareOpenGraphContent shareOpenGraphContent = new ShareOpenGraphContent.Builder().setAction(shareOpenGraphAction).build();
    ShareContentValidation.validateForMessage(shareOpenGraphContent);
}
Also used : ShareOpenGraphAction(com.facebook.share.model.ShareOpenGraphAction) ShareOpenGraphContent(com.facebook.share.model.ShareOpenGraphContent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)14 ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)9 Test (org.junit.Test)6 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 FacebookException (com.facebook.FacebookException)3 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