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); }
private static JSONObject toJSONObject( final ShareOpenGraphObject object, final PhotoJSONProcessor photoJSONProcessor) throws JSONException { final JSONObject result = new JSONObject(); final Set<String> keys = object.keySet(); for (String key : keys) { result.put(key, toJSONValue(object.get(key), photoJSONProcessor)); } return result; }
public static Object toJSONValue( @Nullable final Object object, final PhotoJSONProcessor photoJSONProcessor) throws JSONException { if (object == null) { return JSONObject.NULL; } if ((object instanceof String) || (object instanceof Boolean) || (object instanceof Double) || (object instanceof Float) || (object instanceof Integer) || (object instanceof Long)) { return object; } if (object instanceof SharePhoto) { if (photoJSONProcessor != null) { return photoJSONProcessor.toJSONObject((SharePhoto) object); } return null; } if (object instanceof ShareOpenGraphObject) { return toJSONObject((ShareOpenGraphObject) object, photoJSONProcessor); } if (object instanceof List) { return toJSONArray((List) object, photoJSONProcessor); } throw new IllegalArgumentException( "Invalid object found for JSON serialization: " +object.toString()); }
private static void validateOpenGraphObject( ShareOpenGraphObject openGraphObject, Validator validator) { if (openGraphObject == null) { throw new FacebookException("Cannot share a null ShareOpenGraphObject"); } validator.validate((ShareOpenGraphValueContainer) openGraphObject, true); }
private static void validateOpenGraphValueContainerObject( Object o, Validator validator) { if (o instanceof ShareOpenGraphObject) { validator.validate((ShareOpenGraphObject) o); } else if (o instanceof SharePhoto) { validator.validate((SharePhoto) o); } }
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 void validate(final ShareOpenGraphObject openGraphObject) { validateOpenGraphObject(openGraphObject, this); }