-1

ゲラからFacebookウォールにビデオをアップロードしようとしています ここに私のコードがあります

 byte[] data = null;
    String dataPath = "/mnt/sdcard/DCIM/Camera/video-2012-09-03-13-34-19.mp4";
    Bundle param;
   //video extension
    data Name = ".mp4"
    facebook = new Facebook(FB_APP_ID);
    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
    InputStream is = null;
    try {
        is = new FileInputStream(dataPath);
        data = readBytes(is);
        param = new Bundle();
        param.putString("message", "hello guys");
        param.putString("filename", data Name);
        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();
}

最初に、log cat でこのような警告が表示されました

W/Bundle  (  774): Attempt to cast generated internal exception:
W/Bundle  (  774): java.lang.ClassCastException: java.lang.String
W/Bundle  (  774):  at android.os.Bundle.getByteArray(Bundle.java:1305)
W/Bundle  (  774):  at com.facebook.android.Util.openUrl(Util.java:172)
W/Bundle  (  774):  at com.facebook.android.Facebook.request(Facebook.java:751)
W/Bundle  (  774):  at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:253)
W/Bundle  (  774): Key format expected byte[] but value was a java.lang.String.  The default value <null> was returned.
W/Bundle  (  774): Attempt to cast generated internal exception:
W/Bundle  (  774): java.lang.ClassCastException: java.lang.String
W/Bundle  (  774):  at android.os.Bundle.getByteArray(Bundle.java:1305)
W/Bundle  (  774):  at com.facebook.android.Util.openUrl(Util.java:172)
W/Bundle  (  774):  at com.facebook.android.Facebook.request(Facebook.java:751)

Google で検索すると、Util.java のいくつかの行を変更するよう提案されたため、Facebook API にバグがあると示唆する人もいます。

for (String key : parameters.keySet()) {
            if (parameters.get(key) instanceof byte[]) {

                continue;
            }

            sb.append("Content-Disposition: form-data; name=\"" + key
                    + "\"\r\n\r\n" + parameters.getString(key));
            sb.append("\r\n" + "--" + boundary + "\r\n");
        }

        return sb.toString();
    }

for (String key : params.keySet()) {
                if (params.get(key) instanceof byte[]) {
                    dataparams.putByteArray(key, params.getByteArray(key));
                }
            }

現在、警告やエラーは発生していませんが、ビデオがアップロードされていません。助けてください。

前もって感謝します

4

2 に答える 2

0

ほんの数日前にこのスタックオーバーフローの投稿を使用して、ビデオのアップロードが正しく機能するようにしました。最初からやり直して、その回答の指示に正確に従って、それを機能させます。今日だけでうまくいったので、うまくいくことを私は知っています。

于 2012-09-07T18:24:04.120 に答える