use of com.facebook.share.ShareApi 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.ShareApi in project react-native-fbsdk by facebook.
the class FBShareAPIModule method canShare.
/**
* Check if the content can be shared.
* @param shareContentMap must be a valid {@link ShareContent}
* @param promise Use promise to pass the result to JS.
*/
@ReactMethod
public void canShare(ReadableMap shareContentMap, Promise promise) {
ShareContent shareContent = Utility.buildShareContent(shareContentMap);
if (shareContent != null) {
ShareApi shareApi = new ShareApi(shareContent);
promise.resolve(shareApi.canShare());
} else {
promise.reject("ShareContent cannot be null");
}
}
use of com.facebook.share.ShareApi in project react-native-fbsdk by facebook.
the class FBShareAPIModule method share.
/**
* Share the content.
* @param shareContentMap must be a valid {@link ShareContent}.
* @param graphNode The graph node to share to (this can be a user id, event id, page id, group id, album
* id, etc).
* @param message The custom message that will accompany the share content.
* @param promise Use promise to pass share api result to JS.
*/
@ReactMethod
public void share(ReadableMap shareContentMap, String graphNode, String message, Promise promise) {
ShareContent shareContent = Utility.buildShareContent(shareContentMap);
if (shareContent != null) {
ShareApi shareApi = new ShareApi(shareContent);
shareApi.setGraphNode(graphNode);
shareApi.setMessage(message);
shareApi.share(new ShareAPICallback(promise));
} else {
promise.reject("ShareContent cannot be null");
}
}
use of com.facebook.share.ShareApi 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.ShareApi in project facebook-android-sdk by facebook.
the class RequestTests method testUploadVideoFile.
@LargeTest
public void testUploadVideoFile() throws IOException, URISyntaxException {
File tempFile = null;
try {
tempFile = createTempFileFromAsset("DarkScreen.mov");
ShareVideo video = new ShareVideo.Builder().setLocalUrl(Uri.fromFile(tempFile)).build();
ShareVideoContent content = new ShareVideoContent.Builder().setVideo(video).build();
final ShareApi shareApi = new ShareApi(content);
final AtomicReference<String> videoId = new AtomicReference<>(null);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
shareApi.share(new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
videoId.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(videoId.get());
} catch (Exception ex) {
fail();
} finally {
if (tempFile != null) {
tempFile.delete();
}
}
}
Aggregations