Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending image with fbchat
#1
Hello,

i've started recently working with Python and i want to learn to send automatic messages with fbchat.

I cand send a text message, i can send an Emoji, but the problem is when i try sending a picture from my PC, it doesn't work.
The image is located in "D:/downloads" and the name of the picture is "1623622_833937009956843_569272768_n". Can you please help me ?

import fbchat
from fbchat import Client
from fbchat.models import *
import time
from datetime import datetime
from apscheduler.schedulers.blocking import BlockingScheduler

path = 'D:\Downloads'

def mesaj_fb():

 client = fbchat.Client("username", "password")
 friend = client.searchForUsers("friend's name")
 id = friend[0].uid
 client.sendMessage('Tick! La semnalul urmator va fi ora: %s' % datetime.now(), id)
 client.send(Message(emoji_size=EmojiSize.SMALL), id)
 client.sendLocalImage(id,message='<message text>',image='1623622_833937009956843_569272768_n')

sched = BlockingScheduler()

sched.add_job(mesaj_fb, 'interval', minutes=1)

sched.start()
The log looks like this:

Job "mesaj_fb (trigger: interval[0:01:00], next run at: 2019-12-30 20:57:46 EET)" raised an exception
Traceback (most recent call last):
File "C:\Users......\base.py", line 125, in run_job
retval = job.func(*job.args, **job.kwargs)
File "C:/Users/..../fb chat.py", line 17, in mesaj_fb
client.sendLocalImage(id,message='<message text>',image='1623622_833937009956843_569272768_n')
TypeError: sendLocalImage() got an unexpected keyword argument 'image'

Process finished with exit code -1
Reply
#2
If look at doc there is no parameter image.
You may look at old code where the did use image parameter,and now have removed that.
Then it will be like this:
from fbchat import Client
from fbchat.models import *

client = Client("<email>", "<password>")
thread_id = "1234567890"
thread_type = ThreadType.GROUP

# You most have this image in Dowloads folder
path_image = r'D:\Downloads\image.png'

client.sendLocalImage(
    path_image,
    message=Message(text="This is a local image"),
    thread_id=thread_id,
    thread_type=thread_type,
)
Reply
#3
(Dec-30-2019, 08:25 PM)snippsat Wrote: If look at doc there is no parameter image.
You may look at old code where the did use image parameter,and now have removed that.
Then it will be like this:
from fbchat import Client
from fbchat.models import *

client = Client("<email>", "<password>")
thread_id = "1234567890"
thread_type = ThreadType.GROUP

# You most have this image in Dowloads folder
path_image = r'D:\Downloads\image.png'

client.sendLocalImage(
    path_image,
    message=Message(text="This is a local image"),
    thread_id=thread_id,
    thread_type=thread_type,
)

Thank you very much, it's clear now. I've also managed to send a remote image :)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020