use of com.facebook.share.model.ShareOpenGraphAction in project android-oss by kickstarter.
the class ThanksActivity method startShareOnFacebook.
private void startShareOnFacebook(@NonNull final 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();
shareDialog.show(content);
}
use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.
the class RequestTests method testShareOpenGraphContentWithBadType.
@LargeTest
public void testShareOpenGraphContentWithBadType() throws Exception {
ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").build();
ShareOpenGraphAction ogAction = new ShareOpenGraphAction.Builder().setActionType(TEST_OG_ACTION_TYPE + "bad").putObject("test", ogObject).build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(ogAction).setPreviewPropertyName("test").build();
final ShareApi shareApi = new ShareApi(content);
final AtomicReference<String> actionId = new AtomicReference<>(null);
final AtomicBoolean errorOccurred = new AtomicBoolean(false);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
shareApi.share(new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
actionId.set(result.getPostId());
notifyShareFinished();
}
@Override
public void onCancel() {
notifyShareFinished();
}
@Override
public void onError(FacebookException error) {
errorOccurred.set(true);
notifyShareFinished();
}
private void notifyShareFinished() {
synchronized (shareApi) {
shareApi.notifyAll();
}
}
});
}
});
synchronized (shareApi) {
shareApi.wait(REQUEST_TIMEOUT_MILLIS);
}
assertNull(actionId.get());
assertTrue(errorOccurred.get());
}
use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.
the class ShareInternalUtility method toJSONObjectForCall.
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");
// 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 JSONArray(peopleIdSet));
}
return actionJSON;
}
use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.
the class RpsFragment method getThrowAction.
private ShareOpenGraphAction getThrowAction() {
// The OG objects have their own bitmaps we could rely on, but in order to demonstrate
// attaching an in-memory bitmap (e.g., a game screencap) we'll send the bitmap explicitly
// ourselves.
ImageButton view = gestureImages[playerChoice];
BitmapDrawable drawable = (BitmapDrawable) view.getBackground();
final Bitmap bitmap = drawable.getBitmap();
return new ShareOpenGraphAction.Builder().setActionType(OpenGraphConsts.THROW_ACTION_TYPE).putString("fb_sample_rps:gesture", getBuiltInGesture(playerChoice)).putString("fb_sample_rps:opposing_gesture", getBuiltInGesture(computerChoice)).putPhotoArrayList("og:image", new ArrayList<SharePhoto>() {
{
add(new SharePhoto.Builder().setBitmap(bitmap).build());
}
}).build();
}
use of com.facebook.share.model.ShareOpenGraphAction in project facebook-android-sdk by facebook.
the class RpsFragment method publishResult.
private void publishResult() {
if (shouldImplicitlyPublish && canPublish()) {
String photoUri = PHOTO_URIS[playerChoice];
SharePhoto.Builder sharePhotoBuilder = new SharePhoto.Builder();
if (photoUri == null) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), DRAWABLES_HUMAN[playerChoice]);
sharePhotoBuilder.setBitmap(bitmap);
} else {
sharePhotoBuilder.setImageUrl(Uri.parse(photoUri));
}
sharePhotoBuilder.setUserGenerated(false);
final SharePhoto gesturePhoto = sharePhotoBuilder.build();
ShareOpenGraphObject gameObject = createGameObject(gesturePhoto);
ShareOpenGraphAction playAction = createPlayActionWithGame(gameObject);
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(playAction).setPreviewPropertyName("game").build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Log.i(TAG, "Posted OG Action with id: " + result.getPostId());
}
@Override
public void onCancel() {
// This should not happen
}
@Override
public void onError(FacebookException error) {
Log.e(TAG, "Play action creation failed: " + error.getMessage());
}
});
}
}
Aggregations