gpt4 book ai didi

java - 发布视频时总是提示视频格式不受支持

转载 作者:行者123 更新时间:2023-12-02 08:07:15 25 4
gpt4 key购买 nike

我正在尝试使用图形 API 将视频上传到用户墙。结果始终是错误响应“{”error”:{“message”:“(#352) Video file format is not support”,“type”:“OAuthException”}}”。我尝试了几种不同的视频类型,这些类型都基于此列表受支持,http://developers.facebook.com/docs/reference/api/video/ 。根据我对找到的文档的理解,需要做的就是通过 POST 向“https://graph-video.facebook.com/me/videos”发送多部分表单数据请求。顺便说一句,我已经能够使用类似的技术发布照片。我正在使用的代码如下。它基于 http://developers.facebook.com/blog/post/493/ 处的 PHP 示例。 。我已经能够使用 Facebook 上传机制上传不同的视频,所以我知道这些视频适合 Facebook。访问 token 有效,因为我已使用它通过 Graph API 发布照片。

欢迎对我所缺少的内容提出任何建议!

这是我正在使用的 Java 代码:

File video = new File(pathtovideofile);
DataInputStream dis = new DataInputStream(new FileInputStream(video));
byte[] bytes = new byte[(int)video.length()];
dis.read(bytes, 0, (int)video.length());

// set up the http client, the http method, and the multipart entity
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://graph-video.facebook.com/me/videos");
MultipartEntity mpEntity = new MultipartEntity( );

ContentBody cbVideo = new ByteArrayBody(bytes, "video/mp4", "Video Label");
ContentBody cbMessage = new StringBody( "New Video" );
ContentBody cbTitle = new StringBody( "Video Title" );
ContentBody cbAccessToken = new StringBody( accessTokenStr1 );

mpEntity.addPart( "access_token", cbAccessToken );
mpEntity.addPart( "file", cbVideo );
mpEntity.addPart( "description", cbMessage );
mpEntity.addPart( "title", cbTitle );

// put the multipart entity into the request
httppost.setEntity(mpEntity);
// send the request
HttpResponse response = httpclient.execute(httppost);

// get the response entity
HttpEntity resEntity = response.getEntity();
// read the stream and print out the results
InputStream instream = resEntity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
String line;
StringBuilder responsestr = new StringBuilder();
while (( line = reader.readLine()) != null) {
responsestr.append(line);
}
System.out.println(responsestr.toString());

最佳答案

在 php 中这对我有用。首先将文件上传到服务器,然后尝试使用 Graph API 进行 API 调用。

$fbvideo_upload=move_uploaded_file($_FILES['attach_video']['tmp_name'],$fbvideo_path);
chmod($fbvideo_path,0777);
if($fbvideo_upload)
{
$args = array('message' => $status, "access_token" =>$accesstoken,"file"
=> '@'.$fbvideo_path, "title"=>$video_title, "description"=>$video_desc);
$post_url = "https://graph-video.facebook.com/me/videos?access_token=".$accesstoken;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
$data=json_decode($data,true);
if(file_exists($fbvideo_path))
{
@unlink($fbvideo_path);
}
}

关于java - 发布视频时总是提示视频格式不受支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7959055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com