4

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?

Community
  • 1
  • 1
RParadox
  • 6,393
  • 4
  • 23
  • 33

1 Answers1

5

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!")
hygull
  • 8,464
  • 2
  • 43
  • 52
dom
  • 866
  • 8
  • 8
  • 1
    Thanks. Using your solution I get: "facebook.GraphAPIError: An active access token must be used to query information about the current user." I have arrived at something similar, but using a PROFILE_ID. With this I get: ""(#200) The user hasn't authorized the application to perform this action" – RParadox May 23 '13 at 16:45
  • Run your access token through the debugger: https://developers.facebook.com/tools/debug/access_token – dom May 23 '13 at 16:51