在我的应用中,您可以分享您刚拍摄的视频。我想获得视频的链接回到android所以我可以调用另一个将输入数据库中的链接的函数。所以基本上我需要知道如何从我刚刚分享的视频中获取链接。我使用以下代码。
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();
}
}
});
编辑:更改了&#34;字符串atbilde =&#34;所以它会存储视频ID,所以现在我只需要通过简单地添加&#34; https://www.facebook.com/video.php?v=&#34;来构建网址。在id之前。
答案 0 :(得分:0)
如果视频上传成功,您收到的response
应包含id
属性,请参阅
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/videos/#publish
要获取可播放的网址,您可以使用回复中的id
来查询图谱API,如下所示:
/{video_id}?fields=source
查看https://developers.facebook.com/docs/graph-api/reference/v2.1/video/