Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Tutorials
[Python] using python facebook api (noob friendly)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="griimnak" data-source="post: 354749" data-attributes="member: 35695"><p>In this tutorial i'll be showing you how to use facebook's graphAPI in python.</p><p></p><p><em>Pre-requisites:</em></p><ul> <li data-xf-list-type="ul"><em>python 2.7: <a href="https://www.python.org/download/releases/2.7/" target="_blank">Here</a></em></li> </ul><p>Start by downloading the api from facebook: <a href="https://github.com/pythonforfacebook/facebook-sdk" target="_blank">here</a></p><p>unzip it to your desktop, then launch a terminal session and cd into your facebook api directory</p><p><img src="http://i.imgur.com/Hxnrc8o.jpg" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p></p><p>then run the python instal script</p><p>[CODE]python setup.py install[/CODE]</p><p><img src="http://i.imgur.com/2Kdm83V.jpg" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p><img src="http://i.imgur.com/XzDWq1S.jpg" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p></p><p>Now we can delete that facebook folder and start our script.</p><p><img src="http://i.imgur.com/BuVPO8w.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p></p><p>create a new folder and use your desired text editor and save a .py file into it.</p><p><img src="http://i.imgur.com/b56Wlsr.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p></p><p>Now we can start our script, we'll make an auto-liking script for starters.</p><p><img src="http://i.imgur.com/MDFRL3i.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p></p><p>we begin by importing our api library that we installed earlier, you will see this alot in python as you need certain librarys to do certain functions that are not availible in python by default. Think of these librarys as python code plugins</p><p>[CODE]import facebook[/CODE]</p><p></p><p>now we need to generate a token to allow our desired facebook account to use this api and perform tasks, <a href="https://developers.facebook.com/tools/explorer/145634995501895/" target="_blank">click here</a></p><p><img src="http://i.imgur.com/NlaZtxA.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p></p><p>then copy your access token and place it in our token variable</p><p>[CODE]token = "your_token_here"[/CODE]</p><p></p><p>now we can specify the page that we want to auto like, and specify what object we are going to be touching, in this case the posts.</p><p>[CODE]</p><p>profile = graph.get_object("sharefast")</p><p>posts = graph.get_connections(profile['id'], "posts")</p><p>[/CODE]</p><p></p><p>Now we make a simple loop, like each post that is outputed from our graph.get_connections query.</p><p>[CODE]</p><p>for post in posts['data']:</p><p> try:</p><p> graph.put_object(post['id'], "likes")</p><p> print "liking topic: " + post['message']</p><p> except:</p><p> continue</p><p>[/CODE]</p><p></p><p>Here's the whole script:</p><p>[SPOILER=script source]</p><p>[CODE]</p><p>import facebook</p><p></p><p>token = "token here"</p><p></p><p>graph = facebook.GraphAPI(token)</p><p>profile = graph.get_object("sharefast")</p><p>posts = graph.get_connections(profile['id'], "posts")</p><p></p><p>for post in posts['data']:</p><p> try:</p><p> graph.put_object(post['id'], "likes")</p><p> print "liking topic: " + post['message']</p><p> except:</p><p> continue</p><p>[/CODE]</p><p>[/SPOILER]</p><p></p><p>now open a new terminal session again and run the file with this command:</p><p>[CODE]python yourfile.py[/CODE]</p><p><img src="http://i.imgur.com/0UmuW3v.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p><img src="http://i.imgur.com/Lj3Niar.png" alt="" class="fr-fic fr-dii fr-draggable " style="" /> </p><p></p><p>that's as simple as it gets.</p><p>check out theses references to do more cool stuff with this api:</p><p><a href="https://developers.facebook.com/docs/graph-api/reference/" target="_blank">Offical facebook reference</a></p><p><a href="http://facebook-sdk.readthedocs.org/en/latest/api.html" target="_blank">Link</a></p><p></p><p>cheers</p></blockquote><p></p>
[QUOTE="griimnak, post: 354749, member: 35695"] In this tutorial i'll be showing you how to use facebook's graphAPI in python. [I]Pre-requisites:[/I] [LIST] [*][I]python 2.7: [URL='https://www.python.org/download/releases/2.7/']Here[/URL][/I] [/LIST] Start by downloading the api from facebook: [URL='https://github.com/pythonforfacebook/facebook-sdk']here[/URL] unzip it to your desktop, then launch a terminal session and cd into your facebook api directory [IMG]http://i.imgur.com/Hxnrc8o.jpg[/IMG] then run the python instal script [CODE]python setup.py install[/CODE] [IMG]http://i.imgur.com/2Kdm83V.jpg[/IMG] [IMG]http://i.imgur.com/XzDWq1S.jpg[/IMG] Now we can delete that facebook folder and start our script. [IMG]http://i.imgur.com/BuVPO8w.png[/IMG] create a new folder and use your desired text editor and save a .py file into it. [IMG]http://i.imgur.com/b56Wlsr.png[/IMG] Now we can start our script, we'll make an auto-liking script for starters. [IMG]http://i.imgur.com/MDFRL3i.png[/IMG] we begin by importing our api library that we installed earlier, you will see this alot in python as you need certain librarys to do certain functions that are not availible in python by default. Think of these librarys as python code plugins [CODE]import facebook[/CODE] now we need to generate a token to allow our desired facebook account to use this api and perform tasks, [URL='https://developers.facebook.com/tools/explorer/145634995501895/']click here[/URL] [IMG]http://i.imgur.com/NlaZtxA.png[/IMG] then copy your access token and place it in our token variable [CODE]token = "your_token_here"[/CODE] now we can specify the page that we want to auto like, and specify what object we are going to be touching, in this case the posts. [CODE] profile = graph.get_object("sharefast") posts = graph.get_connections(profile['id'], "posts") [/CODE] Now we make a simple loop, like each post that is outputed from our graph.get_connections query. [CODE] for post in posts['data']: try: graph.put_object(post['id'], "likes") print "liking topic: " + post['message'] except: continue [/CODE] Here's the whole script: [SPOILER=script source] [CODE] import facebook token = "token here" graph = facebook.GraphAPI(token) profile = graph.get_object("sharefast") posts = graph.get_connections(profile['id'], "posts") for post in posts['data']: try: graph.put_object(post['id'], "likes") print "liking topic: " + post['message'] except: continue [/CODE] [/SPOILER] now open a new terminal session again and run the file with this command: [CODE]python yourfile.py[/CODE] [IMG]http://i.imgur.com/0UmuW3v.png[/IMG] [IMG]http://i.imgur.com/Lj3Niar.png[/IMG] that's as simple as it gets. check out theses references to do more cool stuff with this api: [URL='https://developers.facebook.com/docs/graph-api/reference/']Offical facebook reference[/URL] [URL='http://facebook-sdk.readthedocs.org/en/latest/api.html']Link[/URL] cheers [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Tutorials
[Python] using python facebook api (noob friendly)
Top