Here's what I did.
First your callback,
private Request.Callback requestCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
if(response.getError() == null) {
Toast.makeText(YourActivity.this, "Posted to Facebook.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(YourActivity.this, "Post to Facebook failed.", Toast.LENGTH_SHORT).show();
}
}
};
Then, see if you have the publish_actions permission already,
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for(String string : subset) {
if(!superset.contains(string)) {
return false;
}
}
return true;
}
Then put this method inside your onClick() method
public void uploadVideoToFb(String caption) {
// Get Facebook's active session.
Session session = Session.getActiveSession();
/*
* Check published permissions first.
*/
List<String> permissionList = session.getPermissions();
if(!isSubsetOf(FacebookFragment.PERMISSIONS, permissionList)) {
/*pendingPublishReauthorization = true;*/
/*
* Set additional permission requests to be able
* to publish on the Facebook feed.
* Inside PERMISSIONS is just "publish_actions".
*/
Session.NewPermissionsRequest newPermissionRequest = new Session.NewPermissionsRequest(this, FacebookFragment.PERMISSIONS);
session.requestNewPublishPermissions(newPermissionRequest);
return;
}
new TaskDownloadAndPostToFb(this, caption).execute();
}
Our publish_action permission,
public static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
Then here's my AsyncTask,
@Override
public void onPostExecute(Integer result) {
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath() + filename;
File videoFile = new File(baseDir);
if(videoFile.exists()) {
Session session = Session.getActiveSession();
if(session != null) {
try {
Request request = Request.newUploadVideoRequest(session, videoFileLocal, requestCallback);
/*
* Take note of where to get the reference
of your bundle, it should always be
request.getParameters()
*/
Bundle params = request.getParameters();
params.putString("description", this.caption);
request.setParameters(params);
request.executeAsync();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
} else {
Log.i(TAG, "Video not found.");
}
}
Also, I have edited a lot of my code, of course, for security reasons. Let me know if something is lacking and broken.
I'm using Facebook's latest SDK 3.17 as of August 7, 2014