Search in sources :

Example 6 with SharePhotoContent

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

the class RequestTests method testExecuteUploadPhotoToAlbum.

@LargeTest
public void testExecuteUploadPhotoToAlbum() throws InterruptedException, JSONException {
    // first create an album
    Bundle params = new Bundle();
    params.putString("name", "Foo");
    GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "me/albums", params, HttpMethod.POST);
    GraphResponse response = request.executeAndWait();
    JSONObject jsonResponse = response.getJSONObject();
    assertNotNull(jsonResponse);
    String albumId = jsonResponse.optString("id");
    assertNotNull(albumId);
    // upload an image to the album
    Bitmap image = createTestBitmap(128);
    SharePhoto photo = new SharePhoto.Builder().setBitmap(image).setUserGenerated(true).build();
    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
    final ShareApi shareApi = new ShareApi(content);
    shareApi.setGraphNode(albumId);
    final AtomicReference<String> imageId = new AtomicReference<>(null);
    getActivity().runOnUiThread(new Runnable() {

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

                @Override
                public void onSuccess(Sharer.Result result) {
                    imageId.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(imageId.get());
    // now check to see if the image is in the album
    GraphRequest listRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), albumId + "/photos");
    GraphResponse listResponse = listRequest.executeAndWait();
    JSONObject listObject = listResponse.getJSONObject();
    assertNotNull(listObject);
    JSONArray jsonList = listObject.optJSONArray("data");
    assertNotNull(jsonList);
    boolean found = false;
    for (int i = 0; i < jsonList.length(); i++) {
        JSONObject imageObject = jsonList.getJSONObject(i);
        if (imageId.get().equals(imageObject.optString("id"))) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) Bundle(android.os.Bundle) JSONArray(org.json.JSONArray) AtomicReference(java.util.concurrent.atomic.AtomicReference) Bitmap(android.graphics.Bitmap) JSONObject(org.json.JSONObject) SharePhoto(com.facebook.share.model.SharePhoto) Sharer(com.facebook.share.Sharer) ShareApi(com.facebook.share.ShareApi) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 7 with SharePhotoContent

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

the class PostsRequest method makePublishPostRequest.

public static void makePublishPostRequest(Uri attachmentUri, FacebookCallback<Sharer.Result> callback) {
    SharePhoto photo = new SharePhoto.Builder().setImageUrl(attachmentUri).build();
    SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
    ShareApi.share(content, callback);
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) SharePhoto(com.facebook.share.model.SharePhoto)

Example 8 with SharePhotoContent

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

the class ShareContentValidationTest method testItValidatesMaxSizeOfPhotoShareByMessage.

@Test(expected = FacebookException.class)
public void testItValidatesMaxSizeOfPhotoShareByMessage() {
    SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder().addPhoto(buildSharePhoto("https://facebook.com/awesome-1.gif")).addPhoto(buildSharePhoto("https://facebook.com/awesome-2.gif")).addPhoto(buildSharePhoto("https://facebook.com/awesome-3.gif")).addPhoto(buildSharePhoto("https://facebook.com/awesome-4.gif")).addPhoto(buildSharePhoto("https://facebook.com/awesome-5.gif")).addPhoto(buildSharePhoto("https://facebook.com/awesome-6.gif")).addPhoto(buildSharePhoto("https://facebook.com/awesome-7.gif")).build();
    ShareContentValidation.validateForMessage(sharePhotoContent);
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with SharePhotoContent

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

the class ShareContentValidationTest method testItValidatesNullImageForPhotoShareByMessage.

// -PhotoContent
@Test(expected = FacebookException.class)
public void testItValidatesNullImageForPhotoShareByMessage() {
    SharePhotoContent.Builder spcBuilder = new SharePhotoContent.Builder();
    SharePhoto sharePhoto = new SharePhoto.Builder().setImageUrl(null).setBitmap(null).build();
    SharePhotoContent sharePhotoContent = spcBuilder.addPhoto(sharePhoto).build();
    ShareContentValidation.validateForMessage(sharePhotoContent);
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) SharePhoto(com.facebook.share.model.SharePhoto) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with SharePhotoContent

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

the class ShareContentValidationTest method testItValidatesEmptyListOfPhotoForPhotoShareByMessage.

@Test(expected = FacebookException.class)
public void testItValidatesEmptyListOfPhotoForPhotoShareByMessage() {
    SharePhotoContent sharePhoto = new SharePhotoContent.Builder().build();
    ShareContentValidation.validateForMessage(sharePhoto);
}
Also used : SharePhotoContent(com.facebook.share.model.SharePhotoContent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SharePhotoContent (com.facebook.share.model.SharePhotoContent)11 SharePhoto (com.facebook.share.model.SharePhoto)6 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Bundle (android.os.Bundle)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 Bitmap (android.graphics.Bitmap)2 FacebookException (com.facebook.FacebookException)2 ShareLinkContent (com.facebook.share.model.ShareLinkContent)2 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)2 ShareVideoContent (com.facebook.share.model.ShareVideoContent)2 List (java.util.List)2 JSONException (org.json.JSONException)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)1 AccessToken (com.facebook.AccessToken)1 ShareApi (com.facebook.share.ShareApi)1 Sharer (com.facebook.share.Sharer)1 ShareCameraEffectContent (com.facebook.share.model.ShareCameraEffectContent)1 ShareMediaContent (com.facebook.share.model.ShareMediaContent)1