获取刚刚在Facebook上发布的视频网址

时间:2013-07-24 15:26:07

标签: android facebook url video facebook-android-sdk

在我的代码上,我在Facebook上发布了一个视频,很好,但我怎样才能获得该视频的网址?我需要将它存储在一个文件中,以便在另一个时间向用户显示它。 在“响应”字符串中,有链接? 我找不到方法......

这是“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
}

1 个答案:

答案 0 :(得分: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
            }

    }

我希望这个帮助