Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

fb account api grabber

#!/usr/bin/python
# coding: utf-8

import facebook
import urllib
import urlparse
import subprocess
import warnings

# Hide deprecation warnings. The facebook module isn't that up-to-date (facebook.GraphAPIError).
warnings.filterwarnings('ignore', category=DeprecationWarning)


# Parameters of your app and the id of the profile you want to mess with.
FACEBOOK_APP_ID     = 'XXXXXXXXXXXXXXX'
FACEBOOK_APP_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
FACEBOOK_PROFILE_ID = 'XXXXXX'


# Trying to get an access token. Very awkward.
oauth_args = dict(client_id     = FACEBOOK_APP_ID,
                  client_secret = FACEBOOK_APP_SECRET,
                  grant_type    = 'client_credentials')
oauth_curl_cmd = ['curl',
                  'https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(oauth_args)]
oauth_response = subprocess.Popen(oauth_curl_cmd,
                                  stdout = subprocess.PIPE,
                                  stderr = subprocess.PIPE).communicate()[0]

try:
    oauth_access_token = urlparse.parse_qs(str(oauth_response))['access_token'][0]
except KeyError:
    print('Unable to grab an access token!')
    exit()

facebook_graph = facebook.GraphAPI(oauth_access_token)


# Try to post something on the wall.
try:
    fb_response = facebook_graph.put_wall_post('Hello from Python', 
                                               profile_id = FACEBOOK_PROFILE_ID)
    print fb_response
except facebook.GraphAPIError as e:
    print 'Something went wrong:', e.type, e.message
Comment

PREVIOUS NEXT
Code Example
Python :: extract x y coordinates from image in pdf python 
Python :: directory corrente python 
Python :: wxpython menu callback stackoverflow 
Python :: python random password generator 
Python :: scikit learn split data set site:stackoverflow.com 
Python :: python char to hex 
Python :: build an ai writer web crapper 
Python :: taggablemanager serializer django 
Python :: Kernel Ridge et Hyperparameter cross validation sklearn 
Shell :: error: cannot install "code": classic confinement requires snaps under /snap or 
Shell :: run laravel lumen server 
Shell :: pacman remove unused dependencies 
Shell :: what is --use-feature=2020-resolver 
Shell :: list npm packages installed globally 
Shell :: stash untrack files 
Shell :: ubuntu restart mariadb 
Shell :: install nodemon as dev dependency 
Shell :: install nano 
Shell :: install snap on kalicannot communicate with server: Post "http://localhost/v2/snaps/core": dial unix /run/snapd.socket: connect: no such file or directory 
Shell :: uninstall postman ubuntu 
Shell :: curl not found 
Shell :: display nginx logs 
Shell :: yarn install ubuntu 
Shell :: Installing graphviz in Linux 
Shell :: widget tweaks django install 
Shell :: remove 4k video downloader ubuntu 20.04 
Shell :: stop all docker images 
Shell :: @mui/lab install 
Shell :: Create file if not exist bash 
Shell :: how to ignore already committed files in git 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =