【问题标题】:upload / post video by facebook sdk 3.0.1 [closed]通过facebook sdk 3.0.1上传/发布视频[关闭]
【发布时间】:2013-04-28 10:22:51
【问题描述】:

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

喜欢这段代码: Is uploading videos from an SD Card to Facebook possible with the Facebook SDK?

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

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

先谢谢了

【问题讨论】:

  • SirKnigget facebook 的帖子添加了一种新的权限 - “upload_video”。即使是正常工作的应用程序也从未请求过该权限,但无论如何它都会以某种方式上传视频我发现这一点的方式是注意到即使 onComplete 回调也有一条消息,并且该消息中有错误。在我看来非常愚蠢的 SDK 行为 - 如果我有错误,为什么要调用 onComplete() 而不是 onFacebookError()?有人有更多细节。这个问题怎么处理??

标签: android facebook-graph-api


【解决方案1】:

试试这个代码,它正在工作:

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

                        }

【讨论】:

    【解决方案2】:

    这是一个使用 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();
    

    【讨论】:

    • hi muhammad,非常感谢,我尝试将您的代码放在单击按钮方法中,但我收到很多编译器错误,没有任何建议,而且我找不到将视频路径放在哪里?跨度>
    • 从图库中选择视频后,您将通过覆盖onActivityResult获得视频路径
    猜你喜欢
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 2015-02-20
    • 2016-01-28
    相关资源
    最近更新 更多