use of com.facebook.share.model.ShareVideoContent in project facebook-android-sdk by facebook.
the class RequestTests method testUploadVideoFileToUserId.
@LargeTest
public void testUploadVideoFileToUserId() throws IOException, URISyntaxException {
File tempFile = null;
try {
GraphRequest meRequest = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), null);
GraphResponse meResponse = meRequest.executeAndWait();
JSONObject meJson = meResponse.getJSONObject();
assertNotNull(meJson);
String userId = meJson.optString("id");
assertNotNull(userId);
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);
shareApi.setGraphNode(userId);
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