com.facebook.model.OpenGraphObject Java Examples
The following examples show how to use
com.facebook.model.OpenGraphObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FacebookDialogTests.java From FacebookImageShareIntent with MIT License | 6 votes |
public void testOpenGraphObjectImageAttachments() throws JSONException { OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo"); OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar"); action.setProperty("foo", object); FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo"); Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ALPHA_8); builder.setImageAttachmentsForObject("foo", Arrays.asList(bitmap)); List<GraphObject> images = object.getImage(); assertNotNull(images); assertTrue(images.size() == 1); List<String> attachmentNames = builder.getImageAttachmentNames(); assertNotNull(attachmentNames); assertTrue(attachmentNames.size() == 1); String attachmentName = getAttachmentNameFromContentUri((String) images.get(0).getProperty("url")); assertEquals(attachmentNames.get(0), attachmentName); }
Example #2
Source File: FacebookDialogTests.java From FacebookImageShareIntent with MIT License | 5 votes |
public void testCantSetObjectAttachmentsWithNullBitmaps() { try { OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo"); action.setProperty("foo", OpenGraphObject.Factory.createForPost("bar")); FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo"); builder.setImageAttachmentsForObject("foo", Arrays.asList((Bitmap)null)); fail("expected exception"); } catch (NullPointerException exception) { } }
Example #3
Source File: FacebookDialogTests.java From FacebookImageShareIntent with MIT License | 5 votes |
public void testOpenGraphActionAndObjectImageAttachments() throws JSONException { OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo"); OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar"); action.setProperty("foo", object); FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "foo"); Bitmap bitmap = Bitmap.createBitmap(20, 20, Bitmap.Config.ALPHA_8); builder.setImageAttachmentsForAction(Arrays.asList(bitmap)); builder.setImageAttachmentsForObject("foo", Arrays.asList(bitmap)); List<String> attachmentNames = builder.getImageAttachmentNames(); assertNotNull(attachmentNames); assertTrue(attachmentNames.size() == 2); List<GraphObject> objectImages = object.getImage(); assertNotNull(objectImages); assertTrue(objectImages.size() == 1); String attachmentName = getAttachmentNameFromContentUri((String) objectImages.get(0).getProperty("url")); assertTrue(attachmentNames.contains(attachmentName)); List<JSONObject> actionImages = action.getImage(); assertNotNull(actionImages); assertTrue(actionImages.size() == 1); attachmentName = getAttachmentNameFromContentUri((String) actionImages.get(0).getString("url")); assertTrue(attachmentNames.contains(attachmentName)); }
Example #4
Source File: FacebookDialogTests.java From FacebookImageShareIntent with MIT License | 5 votes |
@SuppressWarnings("deprecation") public void testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionType() { try { OpenGraphAction action = OpenGraphAction.Factory.createForPost(); OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar"); action.setProperty("object", object); FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "", "object"); builder.build(); fail("expected exception"); } catch (IllegalArgumentException exception) { } }
Example #5
Source File: FacebookDialogTests.java From FacebookImageShareIntent with MIT License | 5 votes |
@SuppressWarnings("deprecation") public void testOpenGraphDialogBuilderDeprecatedConstructorRequiresActionTypeMatches() { try { OpenGraphAction action = OpenGraphAction.Factory.createForPost("foo"); OpenGraphObject object = OpenGraphObject.Factory.createForPost("bar"); action.setProperty("object", object); FacebookDialog.OpenGraphActionDialogBuilder builder = new FacebookDialog.OpenGraphActionDialogBuilder(getActivity(), action, "notfoo", "object"); builder.build(); fail("expected exception"); } catch (IllegalArgumentException exception) { } }
Example #6
Source File: FacebookDialog.java From Abelana-Android with Apache License 2.0 | 5 votes |
void updateObjectAttachmentUrls(String objectProperty, List<String> attachmentUrls, boolean isUserGenerated) { final OpenGraphObject object; try { object = action.getPropertyAs(objectProperty, OpenGraphObject.class); if (object == null) { throw new IllegalArgumentException("Action does not contain a property '" + objectProperty + "'"); } } catch (FacebookGraphObjectException exception) { throw new IllegalArgumentException("Property '" + objectProperty + "' is not a graph object"); } if (!object.getCreateObject()) { throw new IllegalArgumentException( "The Open Graph object in '" + objectProperty + "' is not marked for creation"); } GraphObjectList<GraphObject> attachments = object.getImage(); if (attachments == null) { attachments = GraphObject.Factory.createList(GraphObject.class); } for (String url : attachmentUrls) { GraphObject graphObject = GraphObject.Factory.create(); graphObject.setProperty(NativeProtocol.IMAGE_URL_KEY, url); if (isUserGenerated) { graphObject.setProperty(NativeProtocol.IMAGE_USER_GENERATED_KEY, true); } attachments.add(graphObject); } object.setImage(attachments); }
Example #7
Source File: FacebookDialog.java From facebook-api-android-maven with Apache License 2.0 | 5 votes |
void updateObjectAttachmentUrls(String objectProperty, List<String> attachmentUrls, boolean isUserGenerated) { final OpenGraphObject object; try { object = action.getPropertyAs(objectProperty, OpenGraphObject.class); if (object == null) { throw new IllegalArgumentException("Action does not contain a property '" + objectProperty + "'"); } } catch (FacebookGraphObjectException exception) { throw new IllegalArgumentException("Property '" + objectProperty + "' is not a graph object"); } if (!object.getCreateObject()) { throw new IllegalArgumentException( "The Open Graph object in '" + objectProperty + "' is not marked for creation"); } GraphObjectList<GraphObject> attachments = object.getImage(); if (attachments == null) { attachments = GraphObject.Factory.createList(GraphObject.class); } for (String url : attachmentUrls) { GraphObject graphObject = GraphObject.Factory.create(); graphObject.setProperty(NativeProtocol.IMAGE_URL_KEY, url); if (isUserGenerated) { graphObject.setProperty(NativeProtocol.IMAGE_USER_GENERATED_KEY, true); } attachments.add(graphObject); } object.setImage(attachments); }