Search This Blog

Thursday 24 December 2015

Use facebook SDK in PYTHON


1. Download facebook-sdk from developers.facebook.com

OR

1. Download facebook-sdk from here
https://codeload.github.com/pythonforfacebook/facebook-sdk/zip/master


2. Extract zip file and click on setup.py
3. Open cmd and goto downloads(facebook sdk folder) directory
4. Type python setup.py install

Important Libraries for python

To make your work easier install following things in python:

1. ipython
[write following command in cmd]
pip install ipython

IPython is a command shell for interactive computing in multiple programming languages, originally developed for the Python programming language, that offers introspection, rich media, shell syntax, tab completion, and history. IPython provides the following features:
  • Interactive shells (terminal and Qt-based).
  • A browser-based notebook with support for code, text, mathematical expressions, inline plots and other media.
  • Support for interactive data visualization and use of GUI toolkits.
  • Flexible, embeddable interpreters to load into one's own projects.
  • Tools for parallel computing.

2. jupyter notebook
pip install jupyter

(to open jupyter)
jupyter notebook


The Jupyter Notebook is a web application that allows you to create and share documents
that contain live code, equations, visualizations and explanatory text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more.

3.terminal 
pip install terminado 
(to install terminal in jupyter)

4. numpy
pip install numpy
NumPy is the fundamental package for scientific computing with Python. It contains among other things:
  • a powerful N-dimensional array object
  • sophisticated (broadcasting) functions
  • tools for integrating C/C++ and Fortran code
  • useful linear algebra, Fourier transform, and random number capabilities

5. scipy
pip install scipy
SciPy (pronounced “Sigh Pie”) is a Python-based ecosystem of open-source software for mathematics, science, and engineering. 

6. matplotlib
pip install matplotlib

matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell (ala MATLAB®* or Mathematica®), web application servers, and six graphical user interface toolkits.

7. pandas
pip install pandas

Auto Like Facebook Posts using Python

Auto Like Facebook Posts using Python

We will need following 2 things:
1. Access token
2. Object Id

Where to get this from????

Goto: 
developers.facebook.com->Tools and Support->GraphAPI Explorer

1. Copy access token
2. Click on submit
3. Copy id

Following is the auto-like script:

import facebook
token = "Your access token"
graph = facebook.GraphAPI(token)
profile = graph.get_object("Your object id")
posts = graph.get_connections(profile['id'],"posts")
for post in posts['data']:
    try:
        graph.put_object(post['id'],"likes")
        print "I am liking this topic :" +post["message"]
    except: 

        continue





Auto Like and Auto Comment Facebook posts

Like and comment all the posts on Facebook(using python)

We will need following 2 things:
1. Access token
2. Object Id

Where to get this from????

Goto: 
developers.facebook.com->Tools and Support->GraphAPI Explorer

1. Copy access token
2. Click on submit
3. Copy id

Following is the auto-like and auto-comment script:

import facebook
import re
token = "Paste your access token over Here"
graph = facebook.GraphAPI(token)
#pages = ['rahuldravid']
profile = graph.get_object("Paste Your object Id")
posts = graph.get_connections(profile['id'],"posts") // this line would connect us to the facebook profile
for post in posts['data']:
        try:
            graph.put_object(post['id'],"likes") //this line would like all the posts of facebook
            graph.put_comment(post['id'],message="Long live rahul dravid") // I am going to comment "Long live rahul dravid"
            print "I am commenting :" +post["message"] // Just to check whether our script is working or not...Lets print message
        except:
            continue



// SAVE script with .py extension
//VIEW FOLLOWING VIDEO TO KNOW MORE:
https://www.youtube.com/watch?v=6xSLYgLvu0k