これは、SDK 3.0.1 を使用して Facebook にビデオをアップロードする作業です。お楽しみください...:)
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!permissions.containsAll(PERMISSIONS)) {
this.requestPublishPermissions(session);
this.is_return = true;
return;
}
Session session = Session.getActiveSession();
if (session != null){
Request.Callback requestCallback= new Request.Callback() {
public void onCompleted(Response response) {
final FacebookRequestError error = response.getError();
if(SubmitPost.this.pDialog.isShowing()) {
SubmitPost.this.pDialog.dismiss();
}
if (error != null) {
new AlertDialog.Builder(SubmitPost.this)
.setTitle("Error")
.setMessage(error.getErrorMessage())
.setPositiveButton("OK", null)
.show();
} else {
try {
GraphObject graphObject = response.getGraphObject();
if(graphObject != null) {
JSONObject graphResponse = graphObject.getInnerJSONObject();
postId = graphResponse.getString("id");
SubmitPost.this.write_status.setText("");
if(SubmitPost.this.showDialog) {
SubmitPost.this.showDialog = false;
SubmitPost.this.groups_list.setAdapter(SubmitPost.this.adapter);
new AlertDialog.Builder(SubmitPost.this)
.setTitle("Result")
.setMessage("Your status is posted successfully")
.setPositiveButton("OK", null)
.show();
}
}
} catch (JSONException e) {
Log.i("TAG","JSON error "+ e.getMessage());
Bundle postParams = new Bundle();
final RequestBatch requestBatch = new RequestBatch();
ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
postParams.putParcelable(file.getName(), descriptor);
// byte[] data = Utility.videoEncode(this.file);
// postParams.putByteArray("video", data);
for (final String requestId : requestIds) {
requestBatch.add(new Request(SubmitPost.this.session, requestId+"/videos", postParams, HttpMethod.POST, requestCallback));
}
}
if (!postParams.containsKey(MIGRATION_BUNDLE_PARAM)) {
postParams.putString(MIGRATION_BUNDLE_PARAM, FbSdkVersion.MIGRATION_BUNDLE);
}
}
requestBatch.executeAsync();