-1

Facebook に動画を投稿するアプリを作成しています。次のエラーが表示されます。

08-27 16:51:49.001: W/Facebook-Example(16413): Facebook Error: (#351) Video file was corrupt or invalidnullOAuthException(#351) Video file was corrupt or invalid

これはコードです:

mUploadButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                byte[] data = null;
                AssetFileDescriptor fileDesc = getResources().openRawResourceFd(
                R.raw.test);
                //String dataPath = //"http://commonsware.com/misc/test2.3gp";//"android.resource://com.facebook.android/raw/mo//vie"; //fileDesc.toString();
                String dataMsg = "Your video description here.";
                String dataName = "test.3gp";

                Bundle param;
                AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
                InputStream is ;
                try 
                {
                    is = fileDesc.createInputStream();  
                  // is = new FileInputStream(dataPath);
                    if(is != null)
                    data = readBytes(is);
                    param = new Bundle();
                    param.putString("message", dataMsg);
                    param.putString("filename", dataName);
                    param.putByteArray("video", data);
                    mAsyncRunner.request("me/videos", param, "POST", new SampleRequestListener(), null);
                }
                catch (FileNotFoundException e) {
                   e.printStackTrace();
                }
                catch (IOException e) {
                   e.printStackTrace();
                }       
            }
        });
        mUploadButton.setVisibility(mFacebook.isSessionValid() ?
                View.VISIBLE :
                View.INVISIBLE);

この問題の解決方法を教えてください。よろしくお願いします。

4

1 に答える 1

1

動作していたこのコードを試してみてください。提供されたAPIでfbを少し変更する必要があります。これは、vedio(postimageからvedioへの非同期ランナーの会話)を投稿しようとしているときにすでに行っていることを願っています。少し古い私はそれが今うまくいくかわかりません

   public class SdfgsdActivity extends Activity {
 Facebook facebook = new Facebook("107520172708950");
 byte[] data;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

      /*  facebook.authorize(this, new DialogListener() {
            public void onComplete(Bundle values) {}

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}


        });*/


        Button facebookButton = (Button) findViewById(R.id.button1);
        facebookButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) 
            {
              //  saveButtonDialog.dismiss();

               // saveImageFunction(); // to save the Image

                //facebook.authorize(SdfgsdActivity.this, new String[]{ "user_photos,publish_checkins,publish_actions,publish_stream"},new DialogListener() {                     
                 facebook.authorize(SdfgsdActivity.this, new String[]{ "offline_access,publish_stream,user_videos"},new DialogListener() {                        
                 public void onComplete(Bundle values) 
                 {  
                            postImageonWall1();
                            Log.e("MWR", "No Way to Share!");

                        Toast.makeText(getApplicationContext(), "Video on Facebook.", Toast.LENGTH_SHORT).show();

                    }                      
                    @Override                     
                    public void onFacebookError(FacebookError error) 
                    {                     
                    }                      
                    @Override                     
                    public void onError(DialogError e) 
                    {                     
                    }                      
                    @Override                     
                    public void onCancel() 
                    {                     
                    }                 
                }); 
            }
        });





    }

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

        facebook.authorizeCallback(requestCode, resultCode, data);
    }


    public void postImageonWall() 
    {             
        byte[] data = null;               
        String filename ="image1.jpg";
        String APP_FILE_PATH ="/mnt/sdcard/Recordingimges/";
        Bitmap bi = BitmapFactory.decodeFile(APP_FILE_PATH +filename);
        //Bitmap bi = BitmapFactory.decodeResource(getResources(), R.drawable.icon);             
        ByteArrayOutputStream baos = new ByteArrayOutputStream();              
        bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);              
        data = baos.toByteArray();                
        Bundle params = new Bundle();              
        params.putString(Facebook.TOKEN, facebook.getAccessToken());              
        params.putString("method", "photos.upload");              
        params.putByteArray("picture", data);               
        AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);              
        mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);    
    }
    @SuppressWarnings("unused")
    public void postImageonWall1() 
    {    
           Bundle params = new Bundle();



        byte[] data = null;
        String dataName = "tt.3gp";
        String dataPath = "/mnt/sdcard/Video/tt.3gp";
        String dataMsg = "Your video description here.";
        Bundle param;
         Bundle param1 = null;
        //facebook = new Facebook("107520172708950");
         AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
     InputStream is = null;
        try {
        is = new FileInputStream(dataPath);
        data = readBytes(is);
        param = new Bundle();
        params.putString(Facebook.TOKEN, facebook.getAccessToken());              
        param.putString("filename", dataName);
        param.putString("message", dataMsg);
                param.putString("mimeType", "video/3GP");

        param.putByteArray("video", data);
        mAsyncRunner.request("me/videos", param, "POST", new fbRequestListener(), null);
    }
    catch (FileNotFoundException e) {
       e.printStackTrace();
    }
    catch (IOException e) {
       e.printStackTrace();
    }
    }





    public byte[] readBytes(InputStream inputStream) throws IOException 
    {
        // This dynamically extends to take the bytes you read.
        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();

        // This is storage overwritten on each iteration with bytes.
        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];

        // We need to know how may bytes were read to write them to the byteBuffer.
        int len = 0;
        while ((len = inputStream.read(buffer)) != -1) 
        {
            byteBuffer.write(buffer, 0, len);
        }

        // And then we can return your byte array.
        return byteBuffer.toByteArray();
    }




    public class fbRequestListener implements RequestListener 
    {

        public void onComplete(String response, Object state) 
        {

            Log.d("RESPONSE",""+response);

        }

        public void onIOException(IOException e, Object state) 
        {

            Log.d("RESPONSE",""+e);

        }

        public void onFileNotFoundException(FileNotFoundException e,
                Object state) 
        {

            Log.d("RESPONSE",""+e);

        }

        public void onMalformedURLException(MalformedURLException e,
                Object state) 
        {

        }

        public void onFacebookError(FacebookError e, Object state) 
        {


            Log.d("RESPONSE",""+e);

        }

        }
    }
于 2012-08-27T11:46:01.283 に答える