1

i am getting error in log cat

{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 353, errorType: OAuthException, errorMessage: (#353) Missing video file}, isFromCache:false}

using below Method

 private void postVideo() {         
        try {

            File file = new File(videoPath);

            ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
            Bundle parameters = new Bundle(1);
            parameters.putParcelable(file.getName(), descriptor);

            new Request(Session.getActiveSession(), "me/videos", parameters, HttpMethod.POST, new Request.Callback() {

                @Override
                public void onCompleted(Response response) {                        
                    Constants.showLog(TAG, "In Response " + response.getGraphObject().getProperty("id"));       

                    JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                    String postId = null;
                    try {
                        postId = graphResponse.getString("id");
                        Constants.showLog(TAG, "In Response id " + postId);
                    } catch (JSONException e) {
                        Constants.showLog(TAG,"JSON error "+ e.getMessage());
                    }

                }
            }).executeAsync();


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

please help

Antzi
  • 12,831
  • 7
  • 48
  • 74
Nilesh Verma
  • 914
  • 1
  • 11
  • 26
  • See it..http://stackoverflow.com/questions/10151708/upload-video-to-facebook-in-android?lq=1 – ridoy Dec 27 '12 at 14:15

2 Answers2

3

I see you are using the Android SDK 3.0, and with that we included a simple way to upload videos. Here is my code that I use to upload videos to Facebook:

Request.Callback callback5 = new Request.Callback() {
    public void onCompleted(Response response) {    
        // response will have an id if successful
    }
};
File tempFile;
try {
    tempFile = Util.createTempFileFromAsset(getApplicationContext(), "video.mp4");
    Request request5 = Request.newUploadVideoRequest(session,
                    tempFile, callback5);
    RequestAsyncTask task5 = new RequestAsyncTask(request5);
    task5.execute();
} catch (IOException e) {
    Log.e(Util.TAG, "failed to create temp file");
    e.printStackTrace();
}

and the code for createTempFileFromAsset:

public static File createTempFileFromAsset(Context context, String assetPath) 
    throws IOException {
    InputStream inputStream = null;
    FileOutputStream outStream = null;

    try {
        AssetManager assets = context.getResources().getAssets();
        inputStream = assets.open(assetPath);

        File outputDir = context.getCacheDir(); // context being the
                                                // Activity pointer
        File outputFile = File.createTempFile("prefix", assetPath,
                outputDir);
        outStream = new FileOutputStream(outputFile);

        final int bufferSize = 1024 * 2;
        byte[] buffer = new byte[bufferSize];
        int n = 0;
        while ((n = inputStream.read(buffer)) != -1) {
            outStream.write(buffer, 0, n);
        }

        return outputFile;
    } finally {
        Utility.closeQuietly(outStream);
        Utility.closeQuietly(inputStream);
    }
}
Jesse Chen
  • 4,928
  • 1
  • 20
  • 20
0

pick the file onActivityResult....

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {

        case RESULT_LOAD_IMAGE:
            if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
                Uri selectedImage = data.getData();
                String[] filePathColumn = { MediaStore.Images.Media.DATA };

                Cursor cursor = getContentResolver().query(selectedImage,
                         filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String picturePath = cursor.getString(columnIndex);
                SubmitPost.this.file = new File(SubmitPost.this.file, picturePath);

//              MimeTypeMap mime = MimeTypeMap.getSingleton();
//              String type = mime.getMimeTypeFromExtension(ext);

                cursor.close();
            }
            break;
}

and use

if (!postParams.containsKey(MIGRATION_BUNDLE_PARAM)) {
                            postParams.putString(MIGRATION_BUNDLE_PARAM, FbSdkVersion.MIGRATION_BUNDLE);
                        }

after

ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
            Bundle parameters = new Bundle(1);
            parameters.putParcelable(file.getName(), descriptor);
Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57