0
在我的應用程序中,您可以分享剛剛拍攝的視頻。我想獲取視頻的鏈接回到android,所以我可以調用另一個函數來輸入數據庫中的鏈接。所以基本上我需要知道如何從我剛剛分享的視頻中獲得鏈接。我正在使用下面的代碼。從Facebook上傳的視頻獲取網址
String path;
//get the current active facebook session
Session session = Session.getActiveSession();
//If the session is open
if(session.isOpened()) {
//Get the list of permissions associated with the session
List<String> permissions = session.getPermissions();
//if the session does not have video_upload permission
if(!permissions.contains("video_upload")) {
//Get the permission from user to upload the video to facebook
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(Main_activity.this, Arrays.asList("video_upload"));
session.requestNewReadPermissions(newPermissionsRequest);
}
path = getImagePath(videoUri); //function that gets absolute path
//Create a new file for the video
File file = new File(path);
try {
//create a new request to upload video to the facebook
Request videoRequest = Request.newUploadVideoRequest(session, file, new Request.Callback() {
@Override
public void onCompleted(Response response) {
if(response.getError()==null)
{
Toast.makeText(Main_activity.this, "video shared successfully", Toast.LENGTH_SHORT).show();
Log.i("it","worked");
String atbilde =response.getGraphObject().getProperty("id").toString();
}
else
{
Toast.makeText(Uzdevumi.this, response.getError().getErrorMessage(), Toast.LENGTH_SHORT).show();
}
}
});
//Execute the request in a separate thread
videoRequest.executeAsync();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
//Session is not open
else {
Toast.makeText(getApplicationContext(), "Please login to facebook first", Toast.LENGTH_SHORT).show();
}
}
});
編輯:改變了「字符串atbilde =」所以這將存儲視頻ID,所以現在我只需要通過ID之前簡單地增加「https://www.facebook.com/video.php?v=」打造的URL。