Python 3 Projects
Send Message to Facebook Friend using Python
This time we are going to write python script for sending message to Facebook friend. So, without further delay, let's jump right in.
Step 1: Install Python and It's Library
Download python from here
https://www.python.org/downloads/
Now, install fb module
sudo pip install fbchat ( For Linux Users)
pip install fbchat (For Windows Users)
Step 2: Write and Run the Code
import fbchat
from getpass import getpass
username = str(raw_input("Username: "))
client = fbchat.Client(username, getpass())
no_of_friends = int(raw_input("Number of friends: "))
for i in xrange(no_of_friends):
name = str(raw_input("Name: "))
friends = client.getUsers(name)
friend = friends[0]
msg = str(raw_input("Message: "))
sent = client.send(friend.uid, msg)
if sent:
print("Message has been sent successfully!")

Post a Comment
0 Comments