RequestAsyncTask from Facebook sdk doesn't work for posting video in android

{
    Request request = null;
            RequestAsyncTask task = null ;

        Bundle requestParams    requestParams=new Bundle();
                        byte[] data = downloadUrl(new URL("urltodownload"));
                        requestParams.putByteArray("video", data);
                        requestParams.putString("title", "Video post");
                        requestParams.putString("description", " #SomeTag");
                        request = new Request(Session.getActiveSession(),"me/videos" , requestParams,
                                HttpMethod.POST,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");
                                    }
                                }
                            }
                        });
                        task = new RequestAsyncTask(request);
                        task.execute(); 
                }   

private static byte[] downloadUrl(URL toDownload) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        try {
            byte[] chunk = new byte[4096];
            int bytesRead;
            InputStream stream = toDownload.openStream();

            while ((bytesRead = stream.read(chunk)) > 0) {
                outputStream.write(chunk, 0, bytesRead);
            }

        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }

        return outputStream.toByteArray();
    }

      

{HttpStatus: 500, errorCode: 352, errorType: FacebookApiException, errorMessage: Sorry, the video file you selected is in a format that we don't support.}

I don't know what I am doing wrong, but every time I get this error. is there any other way to post video on facebook wall. I know how to post a newUploadVideoRequest video , but in my case I don't want to download the video and save it to SD card and then post to facebook. There is another way that I can call the api url graph and post the video to facebook wall, but is there any other method so I can post video to facebook wall directly , I almost link to every link

+3


source to share


1 answer


I just change

requestParams.putByteArray ("video", data); requestParams.putByteArray ("video.3gp", data);



And it loaded successfully, you might try the .mp4 also strangely, but there is no helpful documentation as to what should go in the parameters. Hope is useful

+3


source







All Articles