我看到的所有代码,直到现在还没有使用sdk 3.0.1
像这样的代码: Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?我认为这是因为facebook更改了util文件,但我不确定。
如果有人与我们分享(许多开发人员搜索此代码)的工作代码(在sdk 3.0.1上),将成功上传的mp4文件视频从SD卡上传到facebook墙,我将会粘合。
提前谢谢
答案 0 :(得分:4)
尝试使用此代码,它正在运行:
File file=new File(Environment.getExternalStorageDirectory()+"/testvideo.mp4");
try {
Request audioRequest = Request.newUploadVideoRequest(session, file, new Request.Callback() {
@Override
public void onCompleted(Response response) {
// TODO Auto-generated method stub
if(response.getError()==null)
{
Toast.makeText(MainActivity.this, "Video Shared Successfully", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this, response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
}
}
});
audioRequest.executeAsync();
} catch (Exception e) {
e.printStackTrace();
}
答案 1 :(得分:0)
这是一个使用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();