Reputation: 6851
This has been asked several times, but after reading many different posts I still have not a basic version running for posting to a wall.
I want to post to a wall of a FB user with python. The PHP SDK (https://github.com/facebook/facebook-php-sdk) uses this as the first example. I need the equivalent code in python.
require 'facebook-php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
// Get User ID
$user = $facebook->getUser();
The pythonsdk (https://github.com/pythonforfacebook/facebook-sdk) says the basic usage is:
graph = facebook.GraphAPI(oauth_access_token)
Without explaining what that the oauth_access_token is.
According to here: Python - Facebook API - Need a working example one has to generate an access token?
Upvotes: 4
Views: 8054
Reputation: 876
An access token is used to authorize your application to do stuff on the users behalf. There are several ways (also referred to as "flows") to get such a token, you can read up on it here: Facebook Developers Access Tokens. Facebook provides a tool for generating test tokens, you can find it here: Facebook Developers Access Token Tool.
Install facebook module by running the below command (if it isn't installed).
pip install facebook-sdk
Generate a token and run this code to post on your wall:
import facebook
ACCESS_TOKEN = "<your access token>"; # do not forget to add access token here
graph = facebook.GraphAPI(ACCESS_TOKEN)
graph.put_object("me", "feed", message="Hello, World!")
Upvotes: 5