反应| Facebook JS API:尝试将多个图像上传到我的页面Feed时出现错误代码100

问题描述 投票:0回答:1

在第一个函数中,我将多个图像上传到page-id/photos,并获得这些图像的所有ID的正响应。

然而,下一部分是我被困住的地方;我现在正试图在我的Facebook页面时间轴上创建一个包含多个图像的帖子。但是,我得到一个奇怪的错误响应声称我已经上传了我的图像。

我甚至使用Open Graph Explorer从their documentation关注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"
}

我尝试使用Open Graph Explorer

javascript reactjs facebook facebook-graph-api facebook-javascript-sdk
1个回答
0
投票

问题解决了。 出错的部分是我在图片帖子中添加以下内容的地方: data.append("published", true)。 显然,您想要在多张照片中使用的图像必须先设置为published: false才能在帖子中使用。否则,Facebook认为这已经上传。

© www.soinside.com 2019 - 2024. All rights reserved.