Question

I uploaded the videos in facebook using facebook sdk 3.6. I was successfully uploaded the videos but I want to share the location as well while uploading the file. How to do that?

I am using the following code for uploading the video file. I tried but I am not getting. Please can anyone help me on this.

try {
    Request videoRequest = Request
        .newUploadVideoRequest(session,
            file,
            new Request.Callback() {
                @Override
                public void onCompleted(
                    Response response) {
                        if (response
                            .getError() == null) {
                            Toast.makeText(
                               AndroidCamera.this,
                               "video shared successfully",
                               Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(
                               AndroidCamera.this,
                               response.getError().getErrorMessage(),
                               Toast.LENGTH_SHORT).show();
                        }
                    }
                });

    Bundle parameters = videoRequest.getParameters();
    parameters.putString("caption",
            "Video");
    if (Nim_Constants.bUseLocation) {
        parameters.putString("name",
                Nim_Constants.Location);
    }
    parameters
            .putString("link",
                    "https://developers.facebook.com/android");
    videoRequest.setParameters(parameters);
    // Execute the request in a separate thread
    videoRequest.executeAsync();

} catch (FileNotFoundException e) {
    e.printStackTrace();
}
Was it helpful?

Solution

Finally I found solution. It's pretty simple. Use the Request class instead of using newUploadVideoRequest() method because it doesn't allow to pass parameters like title, description. So use the Request class if you want to set the title, desrcription. For this, Just Pass the file as ParcelFileDescriptor and pass location(What ever you have to pass) as description.

Upload Video on Facebook

File file = new File(filepath); try {

ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY);
Bundle parameters = new Bundle();
parameters.putParcelable(file.getName(),descriptor);
parameters.putString("description","Location");

Request videoRequest = new Request(session,"me/videos", parameters,HttpMethod.POST,
                                     new Request.Callback() {

                                            @Override
                                            public void onCompleted(
                                                    Response response) {

                                                if (response.getError() == null) {
                                                    Toast.makeText(
                                                            AndroidCamera.this,
                                                            "video shared successfully",
                                                            Toast.LENGTH_SHORT)
                                                            .show();
                                                } else {
                                                    System.out
                                                            .println(response
                                                                    .getError()
                                                                    .getErrorMessage());
                                                    Toast.makeText(
                                                            AndroidCamera.this,
                                                            response.getError()
                                                                    .getErrorMessage(),
                                                            Toast.LENGTH_SHORT)
                                                            .show();
                                                }
                                            }
                                        });
// Execute the request in a separate thread
videoRequest.executeAsync();

} catch (FileNotFoundException e) {
    e.printStackTrace();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top