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(); }
sharePhotoBuilder.setImageUrl(Uri.parse(photoUri)); sharePhotoBuilder.setUserGenerated(false); final SharePhoto gesturePhoto = sharePhotoBuilder.build();
SharePhoto photo = new SharePhoto.Builder() .setBitmap(image) .setUserGenerated(true) .build(); SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
@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(); } }
@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(); } } }
public static SharePhoto.Builder getPhotoBuilder(final PhotoBuilderType type) { final SharePhoto.Builder builder = new SharePhoto.Builder().setUserGenerated( PHOTO_USER_GENERATED); switch (type) { case BITMAP: builder.setBitmap(PHOTO_BITMAP); break; case LOCAL_URL: builder.setImageUrl(getTestPhotoImageUrl()); break; } return builder; }
@Override public Builder readFrom(final SharePhoto model) { if (model == null) { return this; } return super.readFrom(model) .setBitmap(model.getBitmap()) .setImageUrl(model.getImageUrl()) .setUserGenerated(model.getUserGenerated()) .setCaption(model.getCaption()) ; }