More documentation work, changed addUsersToGroup
back to taking a list of user IDs
Created new README, and finished `intro`
This commit is contained in:
122
README.rst
122
README.rst
@@ -1,118 +1,26 @@
|
||||
======
|
||||
fbchat
|
||||
======
|
||||
fbchat: Facebook Chat (Messenger) for Python
|
||||
============================================
|
||||
|
||||
.. image:: docs/_static/license.svg
|
||||
:target: LICENSE.txt
|
||||
:alt: License: BSD
|
||||
|
||||
Facebook Chat (`Messenger <https://www.messenger.com/>`__) for Python. This project was inspired by `facebook-chat-api <https://github.com/Schmavery/facebook-chat-api>`__.
|
||||
.. image:: docs/_static/python-versions.svg
|
||||
:target: https://pypi.python.org/pypi/fbchat
|
||||
:alt: Supported python versions: 2.7, 3.4, 3.5 and 3.6
|
||||
|
||||
**No XMPP or API key is needed**. Just use your EMAIL and PASSWORD.
|
||||
Facebook Chat (`Messenger <https://www.facebook.com/messages/>`__) for Python.
|
||||
This project was inspired by `facebook-chat-api <https://github.com/Schmavery/facebook-chat-api>`__.
|
||||
|
||||
**No XMPP or API key is needed**. Just use your email and password.
|
||||
|
||||
Installation
|
||||
============
|
||||
Go to `ReadTheDocs <https://fbchat.readthedocs.com>`__ to see the full documentation,
|
||||
or jump right into the code by viewing the `examples`_
|
||||
|
||||
Simple:
|
||||
Installation:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ pip install fbchat
|
||||
|
||||
|
||||
Example Login
|
||||
=============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import fbchat
|
||||
|
||||
client = fbchat.Client('YOUR_EMAIL', 'YOUR_PASSWORD')
|
||||
|
||||
Sending a Message
|
||||
=================
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
friends = client.getUsers("FRIEND'S NAME") # return a list of names
|
||||
friend = friends[0]
|
||||
sent = client.send(friend.uid, "Your Message")
|
||||
if sent:
|
||||
print("Message sent successfully!")
|
||||
# IMAGES
|
||||
client.sendLocalImage(friend.uid,message='<message text>',image='<path/to/image/file>') # send local image
|
||||
imgurl = "http://i.imgur.com/LDQ2ITV.jpg"
|
||||
client.sendRemoteImage(friend.uid,message='<message text>', image=imgurl) # send image from image url
|
||||
|
||||
|
||||
Getting user info from user id
|
||||
==============================
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
friend1 = client.getUsers('<friend name 1>')[0]
|
||||
friend2 = client.getUsers('<friend name 2>')[0]
|
||||
friend1_info = client.getUserInfo(friend1.uid) # returns dict with details
|
||||
both_info = client.getUserInfo(friend1.uid,friend2.uid) # query both together, returns list of dicts
|
||||
friend1_name = friend1_info['name']
|
||||
|
||||
|
||||
Getting last messages sent
|
||||
==========================
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
last_messages = client.getThreadInfo(friend.uid, last_n=20)
|
||||
last_messages.reverse() # messages come in reversed order
|
||||
|
||||
for message in last_messages:
|
||||
print(message.body)
|
||||
|
||||
|
||||
Example Echobot
|
||||
===============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import fbchat
|
||||
#subclass fbchat.Client and override required methods
|
||||
class EchoBot(fbchat.Client):
|
||||
|
||||
def __init__(self,email, password, debug=True, user_agent=None):
|
||||
fbchat.Client.__init__(self,email, password, debug, user_agent)
|
||||
|
||||
def on_message(self, mid, author_id, author_name, message, metadata):
|
||||
self.markAsDelivered(author_id, mid) #mark delivered
|
||||
self.markAsRead(author_id) #mark read
|
||||
|
||||
print("%s said: %s"%(author_id, message))
|
||||
|
||||
#if you are not the author, echo
|
||||
if str(author_id) != str(self.uid):
|
||||
self.send(author_id,message)
|
||||
|
||||
bot = EchoBot("<email>", "<password>")
|
||||
bot.listen()
|
||||
|
||||
|
||||
Saving session
|
||||
==========================
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
session_cookies = client.setSession()
|
||||
# save session_cookies
|
||||
|
||||
|
||||
Loading session
|
||||
==========================
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
client = fbchat.Client(None, None, session_cookies=session_cookies)
|
||||
# OR
|
||||
client.setSession(session_cookies)
|
||||
|
||||
|
||||
Authors
|
||||
=======
|
||||
|
||||
Taehoon Kim / `@carpedm20 <http://carpedm20.github.io/about/>`__
|
||||
© Copyright 2015 - 2017 by Taehoon Kim / `@carpedm20 <http://carpedm20.github.io/about/>`__
|
||||
|
Reference in New Issue
Block a user