First you need to understand what the stream login is . You need to understand if you want to easily switch between different Facebook libraries. Therefore, it may have code that is very verbose for code that is very implementation-based.
The following is that there are various ways to implement OAuth processing and various ways to display and run your web application in Python. It is not possible to authorize without entering the browser. Otherwise, you will need to save a copy of the access_token code in the code.
Suppose you select web.py to handle the presentation of your web application and requests.py to handle the HTTP calls to the Graph API.
import web, requests
Then configure the URL where we want all requests to go through
url = ( '/', 'index' )
Now get your application id, secret address and url after login you want to use
app_id = "YOUR_APP_ID" app_secret = "APP_SECRET" post_login_url = "http://0.0.0.0:8080/"
This code will have one index class to handle logic. In this class we want to deal with authorization code Facebook will return after logging in

user_data = web.input(code=None) code = user_data.code
Set the condition for checking code
if not code:
In the "without authorization" branch, send the user to the dialog box
dialog_url = ( "http://www.facebook.com/dialog/oauth?" + "client_id=" + app_id + "&redirect_uri=" + post_login_url + "&scope=publish_stream" ) return "<script>top.location.href='" + dialog_url + "'</script>"
Otherwise, we can extract the access_token using the code received
token_url = ( "https://graph.facebook.com/oauth/access_token?" + "client_id=" + app_id + "&redirect_uri=" + post_login_url + "&client_secret=" + app_secret + "&code=" + code ) response = requests.get(token_url).content params = {} result = response.split("&", 1) for p in result: (k,v) = p.split("=") params[k] = v access_token = params['access_token']
Here you can choose how you want to deal with the call in order to update the status, for example, a form,
graph_url = ( "https://graph.facebook.com/me/feed?" + "access_token=" + access_token ) return ( '<html><body>' + '\n' + '<form enctype="multipart/form-data" action="' + graph_url + ' "method="POST">' + '\n' + 'Say something: ' + '\n' + '<input name="message" type="text" value=""><br/><br/>' + '\n' + '<input type="submit" value="Send"/><br/>' + '\n' + '</form>' + '\n' + '</body></html>' )
Or using face.py
from facepy import GraphAPI graph = GraphAPI(access_token) try: graph.post( path = 'me/feed', message = 'Your message here' ) except GraphAPI.OAuthError, e: print e.message
So in the end you can get a smaller version, for example
import web from facepy import GraphAPI from urlparse import parse_qs url = ('/', 'index') app_id = "YOUR_APP_ID" app_secret = "APP_SECRET" post_login_url = "http://0.0.0.0:8080/" user_data = web.input(code=None) if not user_data.code: dialog_url = ( "http://www.facebook.com/dialog/oauth?" + "client_id=" + app_id + "&redirect_uri=" + post_login_url + "&scope=publish_stream" ) return "<script>top.location.href='" + dialog_url + "'</script>" else: graph = GraphAPI() response = graph.get( path='oauth/access_token', client_id=app_id, client_secret=app_secret, redirect_uri=post_login_url, code=code ) data = parse_qs(response) graph = GraphAPI(data['access_token'][0]) graph.post(path = 'me/feed', message = 'Your message here')
See details
* Facebook API - Custom feed: http://developers.facebook.com/docs/reference/api/user/#feed
* Post a Facebook photo to Python - Basic Sauce: http://philippeharewood.com/facebook/publish-a-facebook-photo-in-python-the-basic-sauce/
* Facebook and Python - Basic Sauce: http://philippeharewood.com/facebook/facebook-and-python-the-basic-sauce/