0

到目前为止我看到的所有代码都不适用于 sdk 3.0.1

像这样的代码: 是否可以使用 Facebook SDK 将视频从 SD 卡上传到 Facebook?

我认为这是因为 facebook 更改了 util 文件,但我不确定。

如果有人与我们分享(许多搜索此代码的开发人员)工作代码(在 sdk 3.0.1 上),我会很高兴从 sd 卡成功地将 mp4 文件视频上传到 Facebook 墙。

提前谢谢

4

2 回答 2

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();

                        }
于 2013-08-08T12:02:23.647 回答
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();
于 2013-04-29T07:42:52.553 回答