use of com.facebook.share.model.ShareOpenGraphContent 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.ShareOpenGraphContent 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.ShareOpenGraphContent in project facebook-android-sdk by facebook.
the class ShareInternalUtilityTest method testJsonSerializationOfOpenGraphExistingPlace.
@Test
public void testJsonSerializationOfOpenGraphExistingPlace() {
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder().setAction(new ShareOpenGraphAction.Builder().putString("place", "1").build()).setPlaceId("2").build();
try {
JSONObject object = ShareInternalUtility.toJSONObjectForCall(null, content);
assertEquals("1", object.getString("place"));
} catch (JSONException ex) {
// Fail
assertNotNull(ex);
return;
}
}
use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.
the class LegacyNativeDialogParameters method create.
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;
}
use of com.facebook.share.model.ShareOpenGraphContent in project facebook-android-sdk by facebook.
the class NativeDialogParameters method create.
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());
}
} else if (shareContent instanceof ShareMediaContent) {
final ShareMediaContent mediaContent = (ShareMediaContent) shareContent;
List<Bundle> mediaInfos = ShareInternalUtility.getMediaInfos(mediaContent, callId);
nativeParams = create(mediaContent, mediaInfos, shouldFailOnDataError);
} else if (shareContent instanceof ShareCameraEffectContent) {
final ShareCameraEffectContent cameraEffectContent = (ShareCameraEffectContent) shareContent;
// Put Bitmaps behind content uris.
Bundle attachmentUrlsBundle = ShareInternalUtility.getTextureUrlBundle(cameraEffectContent, callId);
nativeParams = create(cameraEffectContent, attachmentUrlsBundle, shouldFailOnDataError);
} else if (shareContent instanceof ShareMessengerGenericTemplateContent) {
final ShareMessengerGenericTemplateContent genericTemplateContent = (ShareMessengerGenericTemplateContent) shareContent;
nativeParams = create(genericTemplateContent, shouldFailOnDataError);
} else if (shareContent instanceof ShareMessengerOpenGraphMusicTemplateContent) {
final ShareMessengerOpenGraphMusicTemplateContent openGraphMusicTemplateContent = (ShareMessengerOpenGraphMusicTemplateContent) shareContent;
nativeParams = create(openGraphMusicTemplateContent, shouldFailOnDataError);
} else if (shareContent instanceof ShareMessengerMediaTemplateContent) {
final ShareMessengerMediaTemplateContent mediaTemplateContent = (ShareMessengerMediaTemplateContent) shareContent;
nativeParams = create(mediaTemplateContent, shouldFailOnDataError);
}
return nativeParams;
}
Aggregations