Javascript React | Facebook JS API:尝试将多个图像上载到我的页面提要时出现错误代码100
在第一个函数中,我将多个图像上载到Javascript React | Facebook JS API:尝试将多个图像上载到我的页面提要时出现错误代码100,javascript,reactjs,facebook,facebook-graph-api,facebook-javascript-sdk,Javascript,Reactjs,Facebook,Facebook Graph Api,Facebook Javascript Sdk,在第一个函数中,我将多个图像上载到页面id/photos,并收到这些图像的所有id的肯定响应 然而,下一部分是我被困的地方;我现在正试图在我的Facebook页面时间线上创建一个包含多个图像的帖子。然而,我收到一个奇怪的错误回复,声称我已经上传了我的图片 我甚至在使用Open Graph Explorer时也使用了Facebook自己的示例,但这只会返回另一个错误 发送图像的功能: (工作正常) 错误代码 打开图形浏览器的我的尝试 问题已解决 出错的地方是我在图片帖子中添加了以下内容: data
页面id/photos
,并收到这些图像的所有id的肯定响应
然而,下一部分是我被困的地方;我现在正试图在我的Facebook页面时间线上创建一个包含多个图像的帖子。然而,我收到一个奇怪的错误回复,声称我已经上传了我的图片
我甚至在使用Open Graph Explorer时也使用了Facebook自己的示例,但这只会返回另一个错误
发送图像的功能:
(工作正常)
错误代码
打开图形浏览器的我的尝试
问题已解决出错的地方是我在图片帖子中添加了以下内容:
data.append(“published”,true)
显然,要在多照片帖子中使用的图像必须设置为
published:false
,才能在帖子中使用。否则,Facebook认为这已经上传了
sendFacebookImagePost(page) {
const attached_media = []
for(let i = 0; i < this.state.upload_imgsrc.length; i++) {
let reader = new FileReader();
reader.onload = (e) => {
let arrayBuffer = e.target.result;
let blob = new Blob([arrayBuffer], { type: this.state.upload_imgsrc[i].type });
let data = new FormData()
data.append("source", blob)
data.append("message", this.state.fb_message)
data.append("no_story", true)
data.append("published", true)
axios({
method: "post",
url: "https://graph.facebook.com/" + page.id + "/photos?access_token=" + page.accessToken,
data: data
})
.then(response => {
attached_media.push({media_fbid: response.data.id})
if (attached_media.length === this.state.upload_imgsrc.length) {
this.sendFacebookPost(page, attached_media)
}
})
.catch(error => {
console.log(error);
})
}
reader.readAsArrayBuffer(this.state.upload_imgsrc[i]);
}
}
sendFacebookPost(page, attached_media) {
let data = {
message: this.state.fb_message,
link: this.state.fb_link,
attached_media: attached_media
// this is what attached_media returns:
// [
// {media_fbid: response.data.id},
// {media_fbid: response.data.id}
// ]
}
axios({
method: "post",
url: "https://graph.facebook.com/" + page.id + "/feed?access_token=" + page.accessToken,
data: data
})
.then( () => this.setState({fb_successMessage: "Post successful!", fb_errorMessage: ""}) )
.catch(error => {
console.log(error);
})
}
error: {
code: 100
error_subcode: 1366051
error_user_msg: "These photos were already posted."
error_user_title: "Already Posted"
fbtrace_id: "Cl9TUTntOZK"
is_transient: false
message: "Invalid parameter"
type: "OAuthException"
}