|
#!/usr/bin/env python |
|
|
|
import requests |
|
|
|
|
|
def main(): |
|
|
|
""" |
|
The following is an example of how to share a link on a Facebook Fan page |
|
programmatically. In my test I got the OAUTH_ACCESS_TOKEN using my |
|
browser. I'm still trying to figure out how to get the |
|
AUTH_ACCESS_TOKEN programmatically. |
|
|
|
For this example to work you need to first install https://github.com/kennethreitz/requests |
|
|
|
To get the access the AUTH_ACCESS_TOKEN token do the following: |
|
|
|
1. Setup a an website app by going to |
|
https://developers.facebook.com/apps and then create a new website app. |
|
|
|
2. Go to the URL to gave Facebook for your "Site URL" when your created |
|
your website app. Example, go to http://example.com/ in your browser if |
|
that's the "Site URL" for your website app. |
|
|
|
3. Go to |
|
https://www.facebook.com/dialog/oauth?client_id=<client_id>&redirect_uri=<site_url>&scope=manage_pages,publish_stream&response_type=token. |
|
Your ``client_id`` is your Facebook App ID and your ``site_url`` is the |
|
same as the redirect_url you used in step 2. This will return you a URL |
|
like, http://www.example.com/#access_token=<access_token>&expires_in=5217. |
|
|
|
4. Go to |
|
https://graph.facebook.com/epicserve/accounts?access_token=<access_token>. |
|
Use the access_token you got from step 3. This will return with a JSON |
|
dictionary that has all the information you need for the constant |
|
variables bellow. |
|
""" |
|
|
|
OAUTH_ACCESS_TOKEN = 'XXXXXXXXXXXX' # the access_token for the page your posting to |
|
PROFILE_ID = 'XXXXXXXXXXXX' # The id of the user or Fan page |
|
LINK_TO_SHARE = 'http://example.com/my-awesome-link-i-want-to-share/' # the link you want to share on your Facebook fan page. |
|
API_URL = 'https://graph.facebook.com/%s/links' % PROFILE_ID |
|
|
|
r = requests.post(API_URL, data={'access_token': OAUTH_ACCESS_TOKEN, 'link': LINK_TO_SHARE}) |
|
print r.headers |
|
print r.content |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
mahal ka ni fetty mwa>♡