use of com.facebook.share.model.ShareOpenGraphObject 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.ShareOpenGraphObject 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.ShareOpenGraphObject in project facebook-android-sdk by facebook.
the class RequestTests method testShareOpenGraphContent.
@LargeTest
public void testShareOpenGraphContent() 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).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);
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) {
notifyShareFinished();
}
private void notifyShareFinished() {
synchronized (shareApi) {
shareApi.notifyAll();
}
}
});
}
});
synchronized (shareApi) {
shareApi.wait(REQUEST_TIMEOUT_MILLIS);
}
assertNotNull(actionId.get());
}
use of com.facebook.share.model.ShareOpenGraphObject in project facebook-android-sdk by facebook.
the class RequestTests method testCreateOpenGraphObjectWithBadImageType.
@LargeTest
public void testCreateOpenGraphObjectWithBadImageType() throws InterruptedException {
// only image urls are accepted for createOpenGraphObject
Bitmap image = createTestBitmap(128);
SharePhoto photo = new SharePhoto.Builder().setBitmap(image).setUserGenerated(true).build();
ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").putPhoto("og:image", photo).build();
try {
GraphRequest request = ShareGraphRequest.createOpenGraphObject(ogObject);
request.executeAndWait();
// should fail because do not accept images without image_url
fail();
} catch (Exception e) {
if (!(e instanceof FacebookException && e.getMessage().equals("Unable to attach images"))) {
fail();
}
}
}
use of com.facebook.share.model.ShareOpenGraphObject in project facebook-android-sdk by facebook.
the class RequestTests method testCreateOpenGraphObject.
@LargeTest
public void testCreateOpenGraphObject() throws InterruptedException {
Uri testImage = Uri.parse("http://i.imgur.com/Diyvl7q.jpg");
SharePhoto photo = new SharePhoto.Builder().setImageUrl(testImage).setUserGenerated(true).build();
ShareOpenGraphObject ogObject = new ShareOpenGraphObject.Builder().putString("og:title", "a title").putString("og:type", TEST_OG_OBJECT_TYPE).putString("og:description", "a description").putPhoto("og:image", photo).build();
try {
GraphRequest request = ShareGraphRequest.createOpenGraphObject(ogObject);
GraphResponse response = request.executeAndWait();
assertNotNull(response);
assertNull(response.getError());
JSONObject graphResult = response.getJSONObject();
assertNotNull(graphResult);
assertNotNull(graphResult.optString("id"));
assertNotNull(response.getRawResponse());
} catch (Exception e) {
fail();
}
}
Aggregations