public static JSONObject toJSONObjectForWeb( final ShareOpenGraphContent shareOpenGraphContent) throws JSONException { ShareOpenGraphAction action = shareOpenGraphContent.getAction(); return OpenGraphJSONUtility.toJSONObject( action, new OpenGraphJSONUtility.PhotoJSONProcessor() { @Override public JSONObject toJSONObject(SharePhoto photo) { Uri photoUri = photo.getImageUrl(); if (!Utility.isWebUri(photoUri)) { throw new FacebookException("Only web images may be used in OG" + " objects shared via the web dialog"); } JSONObject photoJSONObject = new JSONObject(); try { photoJSONObject.put( NativeProtocol.IMAGE_URL_KEY, photoUri.toString()); } catch (JSONException e) { throw new FacebookException("Unable to attach images", e); } return photoJSONObject; } }); }
private static void validateOpenGraphContent( ShareOpenGraphContent openGraphContent, Validator validator) { validator.validate(openGraphContent.getAction()); String previewPropertyName = openGraphContent.getPreviewPropertyName(); if (Utility.isNullOrEmpty(previewPropertyName)) { throw new FacebookException("Must specify a previewPropertyName."); } if (openGraphContent.getAction().get(previewPropertyName) == null) { throw new FacebookException( "Property \"" + previewPropertyName + "\" was not found on the action. " + "The name of the preview property must match the name of an " + "action property."); } }
@Override public Builder readFrom(final com.facebook.share.model.ShareOpenGraphContent model) { if (model == null) { return this; } return super .readFrom(model) .setAction(model.getAction()) .setPreviewPropertyName(model.getPreviewPropertyName()) ; }
final ShareOpenGraphContent content) throws JSONException { final ShareOpenGraphAction action = content.getAction(); final ArrayList<NativeAppCallAttachmentStore.Attachment> attachments = new ArrayList<>(); JSONObject actionJSON = OpenGraphJSONUtility.toJSONObject(
private static Bundle create( ShareOpenGraphContent openGraphContent, JSONObject openGraphActionJSON, boolean dataErrorsFatal) { Bundle params = createBaseParameters(openGraphContent, dataErrorsFatal); Utility.putNonEmptyString( params, ShareConstants.LEGACY_PREVIEW_PROPERTY_NAME, openGraphContent.getPreviewPropertyName()); Utility.putNonEmptyString( params, ShareConstants.LEGACY_ACTION_TYPE, openGraphContent.getAction().getActionType()); Utility.putNonEmptyString( params, ShareConstants.LEGACY_ACTION, openGraphActionJSON.toString()); return params; }
private static Bundle create( ShareOpenGraphContent openGraphContent, JSONObject openGraphActionJSON, boolean dataErrorsFatal) { Bundle params = createBaseParameters(openGraphContent, dataErrorsFatal); // Strip namespace from preview property name String previewProperty = ShareInternalUtility.getFieldNameAndNamespaceFromFullName( openGraphContent.getPreviewPropertyName()).second; Utility.putNonEmptyString( params, ShareConstants.PREVIEW_PROPERTY_NAME, previewProperty); Utility.putNonEmptyString( params, ShareConstants.ACTION_TYPE, openGraphContent.getAction().getActionType()); Utility.putNonEmptyString( params, ShareConstants.ACTION, openGraphActionJSON.toString()); return params; }
public static Bundle create(ShareOpenGraphContent shareOpenGraphContent) { Bundle params = createBaseParameters(shareOpenGraphContent); Utility.putNonEmptyString( params, ShareConstants.WEB_DIALOG_PARAM_ACTION_TYPE, shareOpenGraphContent.getAction().getActionType()); try { JSONObject ogJSON = ShareInternalUtility.toJSONObjectForWeb(shareOpenGraphContent); ogJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject(ogJSON, false); if (ogJSON != null) { Utility.putNonEmptyString( params, ShareConstants.WEB_DIALOG_PARAM_ACTION_PROPERTIES, ogJSON.toString()); } } catch (JSONException e) { throw new FacebookException("Unable to serialize the ShareOpenGraphContent to JSON", e); } return params; }
final ShareOpenGraphAction action = openGraphContent.getAction(); final Bundle parameters = action.getBundle(); this.addCommonParameters(parameters, openGraphContent);
@Test public void testOpenGraphBuilder() { final ShareOpenGraphContent content = ShareModelTestUtility.getOpenGraphContentBuilder().build(); ShareModelTestUtility.assertEquals( ShareModelTestUtility.OPEN_GRAPH_CONTENT_ACTION, content.getAction()); assertEquals( ShareModelTestUtility.OPEN_GRAPH_CONTENT_PREVIEW_PROPERTY_NAME, content.getPreviewPropertyName()); ShareModelTestUtility.assertEquals(content, TestUtils.parcelAndUnparcel(content)); } }