Python 3 Facebook API Bot to Send Messages to Facebook Friends Using Fbchat Module Full Project For Beginners

Python 3 Facebook API Bot to Send Messages to Facebook Friends Using Fbchat Module Full Project For Beginners

 

Welcome folks today in this blog post we will be building a simple facebook bot which will send messages to facebook friends in python using fbchat module. All the full source code of the application will be given below.

 

 

Get Started

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install fbchat

 

After installing this module make an app.py file and copy paste the following code

 

app.py

 

import fbchat 
from getpass import getpass 
username = str(input("Username: ")) 
client = fbchat.Client(username, getpass()) 
no_of_friends = int(input("Number of friends: ")) 
for i in xrange(no_of_friends): 
    name = str(input("Name: ")) 
    friends = client.getUsers(name) # return a list of names 
    friend = friends[0] 
    msg = str(input("Message: ")) 
    sent = client.send(friend.uid, msg) 
    if sent: 
        print("Message sent successfully!")

 

 

Now if you execute the above script by typing the below command as shown below

READ  Python 3 Tkinter Script to Build Ludo Dice Rolling GUI Game Full Project For Beginners

 

python app.py

 

It will ask you to enter the username and password of your facebook account just enter it as shown below

 

Now to find the username for your facebook account just go to the url of your facebook account as shown here

 

 

 

After this the bot will send messages to all your friends

Leave a Reply