在android中将视频发布到facebook

时间:2015-07-23 06:25:40

标签: android facebook-graph-api android-facebook facebook-sdk-3.0

我已成功通过以下代码发布视频

        File file1  = new File( Environment.getExternalStorageDirectory() + File.separator + "a.3gp");
            request = Request.newUploadVideoRequest(Session.getActiveSession(), file1, new Request.Callback() {
                @Override
                public void onCompleted(Response response) {
                    //appLink=null;
                    if (response.getError() == null) {
                        Logs.e(DEBUG_FACEBOOK_PUBLISH, "publish success");
                        if (uploadListener != null) {
                            uploadListener.onSuccess(null);
                        }
                    } else {
                        Logs.e(DEBUG_FACEBOOK_PUBLISH, "publish error: "
                                + response.getError().getErrorMessage());
                        Logs.e(DEBUG_FACEBOOK_PUBLISH, "publish error: "
                                + response.getError().toString());
                        if (uploadListener != null) {
                            uploadListener
                            .onError("Facebook can't publish your content");
                        }
                    }
                }
            });
request.executeAsync();
  

在这种情况下,首先我必须从网址下载视频并保存   它在SD卡之后我可以上传视频usig    newUploadVideoRequest 方法,但在ios中,他们只是传递网址并调用 requestWithGraphPath:@" me / videos" 方法。所以   我们怎么能在Android中这样做,所以我不必下载视频   然后发布它而不是我可以使用它直接发布该视频   网址。

我见过这个网址 https://developers.facebook.com/docs/graph-api/reference/video

1 个答案:

答案 0 :(得分:0)

我正在使用Facebook sdk 3.14,下面的代码工作得很好

Bundle postParams = new Bundle();
postParams.putString("name", give a title);
postParams.putString("type", "link"); 
postParams.putString("link", enclosing url you want to share);    
Request request = new Request(session,"me/feed" , postParams,
            HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();   

这将是回调

Request.Callback callback = new Request.Callback() {
    @Override
    public void onCompleted(Response response) {
      FacebookRequestError error = response.getError();
      if(error!=null){
       something went wrong
     }else{
       successfully posted
      }
    }

}; 

试试这个并提供反馈。