0

在我的代码上,我在 facebook 上发布了一个视频,这很好,但是我怎样才能获得该视频的 url?我需要将其存储在文件中,以便在其他时间向用户显示。在“响应”字符串中,有链接吗?我没找到办法...

这是“PostVideo”类的代码

 AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);

        fbRequestListener temp = new fbRequestListener();
        InputStream is = null;
        try {
            is = new FileInputStream(dataPath);
            data = readBytes(is);
            param = new Bundle();
            param.putString(Facebook.TOKEN, access_token);
            param.putString("message", dataMsg);
            param.putString("filename", ".mp4");
            param.putString("title", TitoloCanzone);
            param.putByteArray("video", data);

            mAsyncRunner.request("me/videos", param, "POST", temp, 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();
    }




    //necessario per il caricamento dei video
    @SuppressWarnings("deprecation")
    class fbRequestListener implements AsyncFacebookRunner.RequestListener{


    @Override
    public void onComplete(String response, Object state) {
        // TODO Auto-generated method stub

        System.out.println("Caricamento completato ");
        //Toast.makeText(getBaseContext(), "caricamento effettuato",Toast.LENGTH_LONG).show();
         mDialog.cancel();
         System.out.print(state.toString());
        //System.out.println(response );

    }

    //here all the exception
}
4

1 回答 1

0

我不知道这是否是最好的方法,但它有效。

在“响应”中,我得到了视频的 ID。我只是用这个字符串“ https://www.facebook.com/photo.php?v= ”来连接它,它是视频代码的完整路径:

@Override
    public void onComplete(String response, Object state) {
        // TODO Auto-generated method stub
         mDialog.cancel();

         String[] temp;
         String UrlVideo = null;
            temp = response.split("\""); //the response string is like "id":"404030"} or {"error":"type of error..."}
            if( temp[1].equalsIgnoreCase("id")){
                //Video caricato e quindi anche trovato
                UrlVideo = "https://www.facebook.com/photo.php?v="+temp[3];
                System.out.println(UrlVideo);
                //qui provvedo ad inoltrarlo al backend
            }

    }

我希望这有帮助

于 2013-07-24T16:03:53.693 回答