Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.93k stars 596 forks source link

Can't upload attachment as Page #849

Open Solarisxcao opened 3 years ago

Solarisxcao commented 3 years ago
const login = require("facebook-chat-api");
const fs = require('fs');
const util = require('util')

file = fs.createReadStream(__dirname + '/{3D}.jpg');
login({email: "xxxxxxx@xxxxx", password: "xxxxxxx"},{pageID: xxxxxxxxxx},(err, api) => {
    if(err) {return console.error(err);
    }
    api.getThreadList(10,null,["INBOX"],(err, list) => {
        if(err) return console.error(err);
        console.log(list);
        let msg = {
            body: "Model",
            attachment: file
        }
        api.sendMessage(msg, list[1].threadID, function callback(err, messageInfo) {
            if(err){ 
                console.log(util.inspect(err,{showHidden:false,depth:null}))
                console.log('err: '+err.errorDescription);
            }
            else {
                console.log('success');
                console.log(messageInfo);
            }
        });
    });
})

I try to upload the image, but the image didn't come out, the error description said can't find attachment. Then I try to login as a user. The image upload successfully. I'm new to node.js and JavaScript. Can someone help me? Great thanks!

Solarisxcao commented 3 years ago

err code:

{
  __ar: 1,
  error: 1545006,
  errorSummary: 'Cannot find attachment',
  hsrp: {
    hblp: { sr_revision: 1003024127, consistency: { rev: 1003024127 } }        
  },
  lid: '6900209483282451074'
}