A standalone HTTP server that implements Facebook's FQL and Graph API.
Python
Switch branches/tags
Nothing to show
Clone or download
Latest commit 9ca7d67 Jan 22, 2014
Permalink
Failed to load latest commit information.
webapp-improved @ 0e6218d add webapp2 submodule Nov 7, 2011
.gitignore .gitignore Oct 24, 2012
.gitmodules add webapp2 submodule Nov 7, 2011
README.md tweak logo in readme Jan 22, 2014
alltests.py add descriptive HTML front page Nov 9, 2011
beer_cap_facebook_logo.png first import; moved from personal repo Oct 29, 2011
download.py the FQL docs are hopelessly out of date, so scraping the FQL schema b… Oct 24, 2012
fql.py add contributing section to README; misc comment tweaks Nov 10, 2011
fql_schema.py the FQL docs are hopelessly out of date, so scraping the FQL schema b… Oct 24, 2012
fql_schema.sql the FQL docs are hopelessly out of date, so scraping the FQL schema b… Oct 24, 2012
fql_test.py check access token if provided Nov 10, 2011
graph.py more s/code.google.com/github/ Jan 4, 2012
graph_on_fql.py add contributing section to README; misc comment tweaks Nov 10, 2011
graph_on_fql_test.py first import; moved from personal repo Oct 29, 2011
graph_schema.py the FQL docs are hopelessly out of date, so scraping the FQL schema b… Oct 24, 2012
graph_test.py Adding support for simple publishing of Facebook data. Nov 21, 2011
mockfacebook.sql add contributing section to README; misc comment tweaks Nov 10, 2011
oauth.py fix server_test.py failure error Nov 18, 2011
oauth_test.py check access token if provided Nov 10, 2011
schemautil.py more s/code.google.com/github/ Jan 4, 2012
server.py more s/code.google.com/github/ Jan 4, 2012
server_test.py Adding support for simple publishing of Facebook data. Nov 21, 2011
testutil.py check access token if provided Nov 10, 2011
webapp2.py add webapp2 submodule Nov 7, 2011

README.md

beer_cap_facebook_logo mockfacebook

mockfacebook is a standalone HTTP server that implements Facebook's FQL and Graph API. It's useful for unit and integration testing and limited manual testing.

It includes a download utility that seeds its database with data and schemas from Facebook, which helps it keep up with Facebook API changes. You can also add your own data manually or programmatically.

mockfacebook is backed by SQLite. It's single threaded, so it's not suitable for load testing, high throughput, or performance.

License: This project is placed in the public domain.

Features

The Graph API is served at the /... endpoint. It supports:

  • read access to all object types except Insights, Permissions, and Subscription
  • aliases as well as ids
  • read access to all connection types except insights, mutualfriends, payments, subscriptions, and Comment/likes
  • multiple selection via ?ids=...
  • checks access token if provided
  • most error codes and messages

FQL is served at the /method/fql.query and /fql endpoints. It supports:

  • full FQL syntax, including subselects
  • read access to all tables except insights and permissions
  • indexable columns. returns an error if a non-indexable column is used in a WHERE clause.
  • all functions: me(), now(), strlen(), substr(), strpos()
  • checks access token if provided
  • JSON and XML output formats
  • most error codes and messages

Right now, the FQL and Graph API use separate data. There's progress toward unifying them, but it's incomplete and would be labor intensive to maintain. Still, feel free to pitch in!

OAuth authentication is served at the /dialog/oauth and /oauth/access_token endpoints. It supports:

  • auth codes
  • access tokens
  • server and client side flows
  • app login

See the issue tracker for a list of other features that may eventually be supported.

Download and setup

No packages or tarballs, just git clone from head!

git clone https://github.com/rogerhu/mockfacebook

mockfacebook depends on webapp2, which comes bundled as a git submodule:

git submodule init
git submodule update

webapp2 also depends on WebOb:

pip install webob  # or sudo apt-get install python-webob

and sqlparse:

# in the mockfacebook dir:
wget http://python-sqlparse.googlecode.com/files/sqlparse-0.1.3.tar.gz
tar xzf sqlparse-0.1.3.tar.gz
ln -s sqlparse-0.1.3/sqlparse sqlparse

Using

First, you'll need data. The easiest way to get some is the download.py script, which downloads your own data and some public data.

You'll need an access token, which you can get from the Graph API Explorer. Click on the Get Access Token button and select all of the permissions under each tab, especially offline_access under Extended Permissions.

Now, run download.py ACCESS_TOKEN. By default, it only downloads a small amount of data. You can use flags like --num_per_type, --crawl_friends, and --graph_ids to get more.

You can also add data to the SQLite database directly. See mockfacebook.sql and fql_schema.sql for the table definitions and, if you've run download.py, graph_data.sql and fql_data.sql for examples. For example:

sqlite3 mockfacebook.db
...
sqlite> INSERT INTO graph_objects(id, alias, data) VALUES(
  '123',
  'fake_user',
  '{"id": "123", "username": "fake_user", "first_name": "John", "last_name": "Doe", ...}');

(You'll need to run download.py or server.py first to create the database file.)

Once you have some data, just run server.py, point your Facebook app at http://localhost:8000/, and start testing!

NOTE: You can supply a --me option, e.g. server.py --me=12345 to designate which id resolves to /me. More work will be done to expand to support multiple page_tokens to correlate this information automatically.

Contributing

Interested in adding features or fixing bugs? Check out the issue tracker for some ideas.

The code base has two top-level applications. download.py downloads FQL and Graph API schemas and data from Facebook. It uses schemautil.py, which defines *Schema and *Dataset DAO classes. The *Dataset classes are only used in the unit tests; the server itself queries the SQLite database directly. Schemas and data are written to *_{data,schema}.{py,sql} and the SQLite db file, mockfacebook.db by default.

server.py serves the data stored in the SQLite db. graph.py, fql.py, and oauth.py are the individual HTTP request handlers served by server.py. oauth.py provides access token checking for the other two, but otherwise they're independent.

download.py and server.py both create the SQLite db, if necessary, and populate it with the OAuth and Graph API tables in mockfacebook.sql and the FQL tables in fql_schema.sql.

The server and handlers have unit tests in *_test.py. You can run them individually or with alltests.py. Please make sure all tests pass before sending patches!

graph_on_fql.py is an incomplete, experimental schema mapping from FQL to Graph API. It serves a Graph API endpoint using the data in the FQL tables. Much of the heavy lifting has already been done, but a fair amount of detail work remains, and it would be labor intensive to maintain, so it's not currently connected. Feel free to check it out though!