Search in sources :

Example 16 with SharePhoto

use of com.facebook.share.model.SharePhoto 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 = GraphRequest.createOpenGraphObject(ogObject);
        GraphResponse response = request.executeAndWait();
        //should fail because do not accept images without imageurl
        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 17 with SharePhoto

use of com.facebook.share.model.SharePhoto 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 = GraphRequest.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

SharePhoto (com.facebook.share.model.SharePhoto)17 Bitmap (android.graphics.Bitmap)6 SharePhotoContent (com.facebook.share.model.SharePhotoContent)5 ShareOpenGraphAction (com.facebook.share.model.ShareOpenGraphAction)4 ArrayList (java.util.ArrayList)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Uri (android.net.Uri)3 LargeTest (android.test.suitebuilder.annotation.LargeTest)3 ShareOpenGraphObject (com.facebook.share.model.ShareOpenGraphObject)3 Bundle (android.os.Bundle)2 Sharer (com.facebook.share.Sharer)2 ShareOpenGraphContent (com.facebook.share.model.ShareOpenGraphContent)2 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 JSONArray (org.json.JSONArray)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 FacebookException (com.facebook.FacebookException)1