1

ログ猫でエラーが発生しています

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

以下の方法を使用する

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

    }

助けてください

4

2 に答える 2

3

あなたは Android SDK 3.0 を使用しているようです。これには、動画をアップロードする簡単な方法が含まれています。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();
}

とのコード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);
    }
}
于 2012-12-27T17:59:39.833 に答える
0

ファイル 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;
}

と使用

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

ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
            Bundle parameters = new Bundle(1);
            parameters.putParcelable(file.getName(), descriptor);
于 2013-04-17T12:38:47.227 に答える