Graph API 发布视频至Facebook页面失败问题求助
问题描述
我正在开发一款应用,支持用户上传图片和视频后发布到Facebook页面。目前图片上传功能正常,access token及相关配置均无问题,但视频上传始终失败。
状态定义
const [file, setFile] = useState([]);
图片上传代码(可正常运行)
const formData = new FormData(); formData.append("source", file); axios.post("https://graph.facebook.com/<pageId>/photos?", formData, { headers: { "Content-Type": "multipart/form-data", "Authorization": "Bearer <access_token>" } } ).then( (res) => { if (res.data["id"]) { alert("上传成功") } } ).catch((err) => { alert("与服务器通信出错") console.log(err) })
视频上传代码(无法正常运行)
const formData = new FormData(); formData.append("file", file); axios.post("https://graph-video.facebook.com/v16.0/<page_id>/videos", formData, { headers: { "Content-Type": "multipart/form-data", "Authorization": "Bearer <same_access_token>" } } ).then( (res) => { if (res.data["id"]) { alert("上传成功") } } ).catch((err) => { alert("与服务器通信出错") console.log(err) })
输入控件及处理函数代码
<input className="btn" type="file" accept="video/mp4,video/x-m4v,video/*" onChange={ (e) => { handleChange(e) } } /> <input className="btn" type="file" accept="image/png, image/jpeg" onChange={ (e) => { handleChange(e) } } />
const handleChange = (e) => { setFile(e.target.files[0]); }
内容的提问来源于stack exchange,提问作者Hasib Aslam
相关产品推荐
相关产品推荐

