public static Bundle create(ShareOpenGraphContent shareOpenGraphContent) { Bundle params = new Bundle(); 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; }
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; }
private static void validate(ShareContent content, Validator validator) throws FacebookException { if (content == null) { throw new FacebookException("Must provide non-null content to share"); } if (content instanceof ShareLinkContent) { validator.validate((ShareLinkContent) content); } else if (content instanceof SharePhotoContent) { validator.validate((SharePhotoContent) content); } else if (content instanceof ShareVideoContent) { validator.validate((ShareVideoContent) content); } else if (content instanceof ShareOpenGraphContent) { validator.validate((ShareOpenGraphContent) content); } }
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."); } }
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(); 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 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 void startShareOnFacebook(final @NonNull Project project) { if (!ShareDialog.canShow(ShareLinkContent.class)) { return; } final Photo photo = project.photo(); final ShareOpenGraphObject object = new ShareOpenGraphObject.Builder() .putString("og:type", "kickstarter:project") .putString("og:title", project.name()) .putString("og:description", project.blurb()) .putString("og:image", photo == null ? null : photo.small()) .putString("og:url", project.webProjectUrl()) .build(); final ShareOpenGraphAction action = new ShareOpenGraphAction.Builder() .setActionType("kickstarter:back") .putObject("project", object) .build(); final ShareOpenGraphContent content = new ShareOpenGraphContent.Builder() .setPreviewPropertyName("project") .setAction(action) .build(); this.shareDialog.show(content); }
public static Bundle create( UUID callId, ShareContent shareContent, boolean shouldFailOnDataError) { Validate.notNull(shareContent, "shareContent"); Validate.notNull(callId, "callId"); Bundle nativeParams = null; if (shareContent instanceof ShareLinkContent) { final ShareLinkContent linkContent = (ShareLinkContent) shareContent; nativeParams = create(linkContent, shouldFailOnDataError); } else if (shareContent instanceof SharePhotoContent) { final SharePhotoContent photoContent = (SharePhotoContent) shareContent; List<String> photoUrls = ShareInternalUtility.getPhotoUrls( photoContent, callId); nativeParams = create(photoContent, photoUrls, shouldFailOnDataError); } else if (shareContent instanceof ShareVideoContent) { final ShareVideoContent videoContent = (ShareVideoContent) shareContent; String videoUrl = ShareInternalUtility.getVideoUrl(videoContent, callId); nativeParams = create(videoContent, videoUrl, shouldFailOnDataError); } else if (shareContent instanceof ShareOpenGraphContent) { final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent; try { JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, openGraphContent); openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject( openGraphActionJSON, false); nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError); } catch (final JSONException e) { throw new FacebookException( "Unable to create a JSON Object from the provided ShareOpenGraphContent: " + e.getMessage()); } } return nativeParams; }
public static Bundle create( UUID callId, ShareContent shareContent, boolean shouldFailOnDataError) { Validate.notNull(shareContent, "shareContent"); Validate.notNull(callId, "callId"); Bundle nativeParams = null; if (shareContent instanceof ShareLinkContent) { final ShareLinkContent linkContent = (ShareLinkContent)shareContent; nativeParams = create(linkContent, shouldFailOnDataError); } else if (shareContent instanceof SharePhotoContent) { final SharePhotoContent photoContent = (SharePhotoContent)shareContent; List<String> photoUrls = ShareInternalUtility.getPhotoUrls( photoContent, callId); nativeParams = create(photoContent, photoUrls, shouldFailOnDataError); } else if (shareContent instanceof ShareVideoContent) { final ShareVideoContent videoContent = (ShareVideoContent)shareContent; nativeParams = create(videoContent, shouldFailOnDataError); } else if (shareContent instanceof ShareOpenGraphContent) { final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent; try { JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, openGraphContent); nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError); } catch (final JSONException e) { throw new FacebookException( "Unable to create a JSON Object from the provided ShareOpenGraphContent: " + e.getMessage()); } } return nativeParams; }
private ShareContent getFacebookShareContent(@NonNull PlaceCheckin theCheckin, @NonNull Place place, String applink) { ShareOpenGraphObject.Builder objectBuilder = new ShareOpenGraphObject.Builder() .putString("og:type", "fitness.course") .putString("og:url", applink) .putString("og:title", getContext().getString(R.string.share_title, place.getName())); if (place.getDescription() != null) { objectBuilder.putString("og:description", place.getDescription()); } if (place.hasLocation()) { objectBuilder.putDouble("fitness:metrics:location:latitude", place.getLocation().getLatitude()); objectBuilder.putDouble("fitness:metrics:location:longitude", place.getLocation().getLongitude()); } // Create an action ShareOpenGraphAction.Builder actionBuilder = new ShareOpenGraphAction.Builder() .setActionType("fitness.walks") .putObject("fitness:course", objectBuilder.build()); if (theCheckin.getImageUrl(SHARE_IMAGE_WIDTH) != null) { SharePhoto photo = new SharePhoto.Builder() .setImageUrl(Uri.parse(theCheckin.getImageUrl(SHARE_IMAGE_WIDTH))) .setUserGenerated(true) .build(); ArrayList<SharePhoto> photoArray = new ArrayList<>(); photoArray.add(photo); actionBuilder.putPhotoArrayList("image", photoArray); } return new ShareOpenGraphContent.Builder() .setPreviewPropertyName("fitness:course") .setAction(actionBuilder.build()) .build(); }
public static Bundle create( UUID callId, ShareContent shareContent, boolean shouldFailOnDataError) { Validate.notNull(shareContent, "shareContent"); Validate.notNull(callId, "callId"); Bundle nativeParams = null; if (shareContent instanceof ShareLinkContent) { final ShareLinkContent linkContent = (ShareLinkContent) shareContent; nativeParams = create(linkContent, shouldFailOnDataError); } else if (shareContent instanceof SharePhotoContent) { final SharePhotoContent photoContent = (SharePhotoContent) shareContent; List<String> photoUrls = ShareInternalUtility.getPhotoUrls( photoContent, callId); nativeParams = create(photoContent, photoUrls, shouldFailOnDataError); } else if (shareContent instanceof ShareVideoContent) { final ShareVideoContent videoContent = (ShareVideoContent) shareContent; nativeParams = create(videoContent, shouldFailOnDataError); } else if (shareContent instanceof ShareOpenGraphContent) { final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent; final ShareOpenGraphAction action = openGraphContent.getAction(); try { JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, action); openGraphActionJSON = ShareInternalUtility.removeNamespacesFromOGJsonObject( openGraphActionJSON, false); nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError); } catch (final JSONException e) { throw new FacebookException( "Unable to create a JSON Object from the provided ShareOpenGraphContent: " + e.getMessage()); } } return nativeParams; }
public static Bundle create( UUID callId, ShareContent shareContent, boolean shouldFailOnDataError) { Validate.notNull(shareContent, "shareContent"); Validate.notNull(callId, "callId"); Bundle nativeParams = null; if (shareContent instanceof ShareLinkContent) { final ShareLinkContent linkContent = (ShareLinkContent)shareContent; nativeParams = create(linkContent, shouldFailOnDataError); } else if (shareContent instanceof SharePhotoContent) { final SharePhotoContent photoContent = (SharePhotoContent)shareContent; List<String> photoUrls = ShareInternalUtility.getPhotoUrls( photoContent, callId); nativeParams = create(photoContent, photoUrls, shouldFailOnDataError); } else if (shareContent instanceof ShareVideoContent) { final ShareVideoContent videoContent = (ShareVideoContent)shareContent; nativeParams = create(videoContent, shouldFailOnDataError); } else if (shareContent instanceof ShareOpenGraphContent) { final ShareOpenGraphContent openGraphContent = (ShareOpenGraphContent) shareContent; final ShareOpenGraphAction action = openGraphContent.getAction(); try { JSONObject openGraphActionJSON = ShareInternalUtility.toJSONObjectForCall( callId, action); nativeParams = create(openGraphContent, openGraphActionJSON, shouldFailOnDataError); } catch (final JSONException e) { throw new FacebookException( "Unable to create a JSON Object from the provided ShareOpenGraphContent: " + e.getMessage()); } } return nativeParams; }
public void validate(final ShareOpenGraphContent openGraphContent) { isOpenGraphContent = true; validateOpenGraphContent(openGraphContent, this); }
public static JSONObject toJSONObjectForCall( final UUID callId, final ShareOpenGraphContent content) throws JSONException { final ShareOpenGraphAction action = content.getAction(); final ArrayList<NativeAppCallAttachmentStore.Attachment> attachments = new ArrayList<>(); JSONObject actionJSON = OpenGraphJSONUtility.toJSONObject( action, new OpenGraphJSONUtility.PhotoJSONProcessor() { @Override public JSONObject toJSONObject(SharePhoto photo) { NativeAppCallAttachmentStore.Attachment attachment = getAttachment( callId, photo); if (attachment == null) { return null; } attachments.add(attachment); JSONObject photoJSONObject = new JSONObject(); try { photoJSONObject.put( NativeProtocol.IMAGE_URL_KEY, attachment.getAttachmentUrl()); if (photo.getUserGenerated()) { photoJSONObject.put(NativeProtocol.IMAGE_USER_GENERATED_KEY, true); } } catch (JSONException e) { throw new FacebookException("Unable to attach images", e); } return photoJSONObject; } }); NativeAppCallAttachmentStore.addAttachments(attachments); // People and place tags must be moved from the share content to the open graph action if (content.getPlaceId() != null) { String placeTag = actionJSON.optString("place"); // Only if the place tag is already empty or null replace with the id from the // share content if (Utility.isNullOrEmpty(placeTag)) { actionJSON.put("place", content.getPlaceId()); } } if (content.getPeopleIds() != null) { JSONArray peopleTags = actionJSON.optJSONArray("tags"); Set<String> peopleIdSet = peopleTags == null ? new HashSet<String>() : Utility.jsonArrayToSet(peopleTags); for (String peopleId : content.getPeopleIds()) { peopleIdSet.add(peopleId); } actionJSON.put("tags", new ArrayList<>(peopleIdSet)); } return actionJSON; }