Java 类com.facebook.share.model.ShareOpenGraphAction 实例源码

项目:kognitivo    文件:ShareInternalUtility.java   
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;
                }
            });
}
项目:android-oss    文件:ThanksShareViewHolder.java   
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);
}
项目:Move-Alarm_ORCA    文件:ShareInternalUtility.java   
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;
                }
            });
}
项目:SocioBlood    文件:ShareInternalUtility.java   
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;
                }
            });
}
项目:kognitivo    文件:OpenGraphJSONUtility.java   
/**
 * Converts an action to a JSONObject.
 *
 * NOTE: All images are removed from the JSON representation and must be added to the builder
 * separately.
 *
 * @param action {@link com.facebook.share.model.ShareOpenGraphAction} to be converted.
 * @return {@link org.json.JSONObject} representing the action.
 * @throws JSONException
 */
public static JSONObject toJSONObject(
        final ShareOpenGraphAction action,
        final PhotoJSONProcessor photoJSONProcessor) throws JSONException {
    final JSONObject result = new JSONObject();
    final Set<String> keys = action.keySet();
    for (String key : keys) {
        result.put(key, toJSONValue(action.get(key), photoJSONProcessor));
    }
    return result;
}
项目:kognitivo    文件:ShareContentValidation.java   
private static void validateOpenGraphAction(
        ShareOpenGraphAction openGraphAction,
        Validator validator) {
    if (openGraphAction == null) {
        throw new FacebookException("Must specify a non-null ShareOpenGraphAction");
    }

    if (Utility.isNullOrEmpty(openGraphAction.getActionType())) {
        throw new FacebookException("ShareOpenGraphAction must have a non-empty actionType");
    }

    validator.validate((ShareOpenGraphValueContainer) openGraphAction, false);
}
项目:SjekkUT    文件:CheckinAndSocialView.java   
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();
}
项目:Move-Alarm_ORCA    文件:OpenGraphJSONUtility.java   
/**
 * Converts an action to a JSONObject.
 *
 * NOTE: All images are removed from the JSON representation and must be added to the builder
 * separately.
 *
 * @param action {@link com.facebook.share.model.ShareOpenGraphAction} to be converted.
 * @return {@link org.json.JSONObject} representing the action.
 * @throws JSONException
 */
public static JSONObject toJSONObject(
        final ShareOpenGraphAction action,
        final PhotoJSONProcessor photoJSONProcessor) throws JSONException {
    final JSONObject result = new JSONObject();
    final Set<String> keys = action.keySet();
    for (String key : keys) {
        result.put(key, toJSONValue(action.get(key), photoJSONProcessor));
    }
    return result;
}
项目:Move-Alarm_ORCA    文件:NativeDialogParameters.java   
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;
}
项目:Move-Alarm_ORCA    文件:ShareContentValidation.java   
private static void validateOpenGraphAction(
        ShareOpenGraphAction openGraphAction,
        Validator validator) {
    if (openGraphAction == null) {
        throw new FacebookException("Must specify a non-null ShareOpenGraphAction");
    }

    if (Utility.isNullOrEmpty(openGraphAction.getActionType())) {
        throw new FacebookException("ShareOpenGraphAction must have a non-empty actionType");
    }

    validator.validate((ShareOpenGraphValueContainer) openGraphAction, false);
}
项目:Move-Alarm_ORCA    文件:ShareInternalUtility.java   
public static JSONObject toJSONObjectForCall(
        final UUID callId,
        final ShareOpenGraphAction action)
        throws JSONException {

    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);

    return actionJSON;
}
项目:Move-Alarm_ORCA    文件:LegacyNativeDialogParameters.java   
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;
}
项目:SocioBlood    文件:OpenGraphJSONUtility.java   
/**
 * Converts an action to a JSONObject.
 *
 * NOTE: All images are removed from the JSON representation and must be added to the builder
 * separately.
 *
 * @param action {@link com.facebook.share.model.ShareOpenGraphAction} to be converted.
 * @return {@link org.json.JSONObject} representing the action.
 * @throws JSONException
 */
public static JSONObject toJSONObject(
        final ShareOpenGraphAction action,
        final PhotoJSONProcessor photoJSONProcessor) throws JSONException {
    final JSONObject result = new JSONObject();
    final Set<String> keys = action.keySet();
    for (String key : keys) {
        result.put(key, toJSONValue(action.get(key), photoJSONProcessor));
    }
    return result;
}
项目:SocioBlood    文件:NativeDialogParameters.java   
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;
}
项目:SocioBlood    文件:ShareContentValidation.java   
private static void validateOpenGraphAction(
        ShareOpenGraphAction openGraphAction,
        Validator validator) {
    if (openGraphAction == null) {
        throw new FacebookException("Must specify a non-null ShareOpenGraphAction");
    }

    if (Utility.isNullOrEmpty(openGraphAction.getActionType())) {
        throw new FacebookException("ShareOpenGraphAction must have a non-empty actionType");
    }

    validator.validate((ShareOpenGraphValueContainer) openGraphAction, false);
}
项目:SocioBlood    文件:ShareInternalUtility.java   
public static JSONObject toJSONObjectForCall(
        final UUID callId,
        final ShareOpenGraphAction action)
        throws JSONException {

    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);

    return actionJSON;
}
项目:SocioBlood    文件:LegacyNativeDialogParameters.java   
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;
}
项目:kognitivo    文件:ShareContentValidation.java   
public void validate(final ShareOpenGraphAction openGraphAction) {
    validateOpenGraphAction(openGraphAction, this);
}
项目:kognitivo    文件:ShareInternalUtility.java   
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;
}
项目:Move-Alarm_ORCA    文件:ShareContentValidation.java   
public void validate(final ShareOpenGraphAction openGraphAction) {
    validateOpenGraphAction(openGraphAction, this);
}
项目:SocioBlood    文件:ShareContentValidation.java   
public void validate(final ShareOpenGraphAction openGraphAction) {
    validateOpenGraphAction(openGraphAction, this);
}