在 android 中将视频发布到 Facebook

Posting video to facebook in android

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

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

in this scenario first i have to download the video from url and save it on the sd card after that i can upload video usig newUploadVideoRequest method but in ios they just passing the url and call the requestWithGraphPath:@"me/videos" method. So how can we do that in android so i don't have to download the video and then post it instead of that i can directly post that video using that url.

我看过这个url https://developers.facebook.com/docs/graph-api/reference/video

我使用的是 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
      }
    }

}; 

试试这个并提供反馈。