[英]React | Facebook JS API : Error code 100 when trying to upload multiple images to my page feed
In a first function, I upload multiple images to page-id/photos
and receive a positive response with all the ids of these images. 在第一个功能中,我将多个图像上传到
page-id/photos
并使用这些图像的所有ID获得肯定响应。
The next part however is where I'm stuck; 然而,下一部分是我被困住的地方; I am now trying to create a post with multiple images to my Facebook page timeline.
我现在正试图在我的Facebook页面时间轴上创建一个包含多个图像的帖子。 However, I'm getting a weird error response claiming that I already have uploaded my images.
但是,我得到一个奇怪的错误响应声称我已经上传了我的图像。
I've even followed Facebook's own example from their documentation using Open Graph Explorer, but that just returns another error 我甚至使用Open Graph Explorer从他们的文档中跟踪Facebook自己的例子,但这只会返回另一个错误
(works without a problem) (没有问题)
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]);
}
}
(Here is where the error happens) (这是错误发生的地方)
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"
}
Problem solved. 问题解决了。
The part that went wrong is where I add the following to my image post: 出错的部分是我在图片帖子中添加以下内容的地方:
data.append("published", true)
. data.append("published", true)
。
Apparently, images you want to use in a multi photo post have to be set to published: false
before they can be used in a post. 显然,要在多张照片中使用的图像必须设置为
published: false
然后才能在帖子中使用它们。 Otherwise, Facebook sees this as already uploaded. 否则,Facebook认为这已经上传。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.