Miłosz Pigłas

Home Facebook Login SDK Notes Contact

Facebook Login SDK

Facebook Login SDK (Download) is Python implementation of Facebook Login Flow. Login function can by used in any business application, that requires access to Facebook Graph API.

How it works

In Facebook Login Flow access token can be obtained on behalf of authenticated user. SDK opens Facebook login form in installed web browser. After successful authentication browser is redirected to URL, that is passed in authentication request. Redirect URL includes parameter, that is used by login SDK to fetch final access_token. When procedure ends, web browser is closed automatically.

Requirements

  1. Installed Chrome or Chromium browser.
  2. Installed Python 3.9 runtime and standard library.
  3. Facebook Application with enabled Facebook Login.

Facebook Login SDK doesn't have dependencies on any third party library.

Usage

  1. You don't need any special installation procedure. Download sdk module and copy it to directory with your application.

  2. Import module and execute function

    get_standalone(
      app_id, 
      app_secret, 
      browser='chrome', 
      redirect='https://example.com', 
      port=None, 
      incognito=False, 
      temp_profile=False
    )
    

    Pass Facebook Application App Id and App Secret. You will find these values in App Dashboard. By default function will try to open Facebook login form in Chrome browser in normal mode and with default profile. After successful authentication user will be redirected to https://example.com. Any URL, that is passed in redirect argument must be defined in application settings. Otherwise Facebook will reject request.

  3. If function end without exception it will return dictionary {'access_token': <str>, 'token_type': 'bearer', 'expires_in': <number> }. You can use value of access_token in requests to Facebook Graph API.

Logging

SDK supports Python Logging framework. You can enable details log by settin DEBUG level in logging module configuration

import logging

logging.basicConfig(level=logging.DEBUG)

Example application

SDK module contains example application, that can be run from command line. After executing python3 fb_login.py it will ask for App Id and App secret and pass it to get_standalone function.

License

Facebook Login SDK is distributed under GNU Affero General Public License. If you need commercial license contact me.

Support

If you need commercial support or you want to report bug, you can send me message in contact form.