Creating and using test Facebook accounts

Dec 16, 2010 15:54 · 267 words · 2 minute read code development facebook

Facebook now allows you to create test users for application development purposes. That doesn’t sound too dramatic in and of itself, but up to now it’s been necessary to create dummy accounts and (technically) violate the terms of service.

Creating new test accounts is a two stage process: firstly obtaining an access token for the application with which the account is to be associated; and then creating the account itself. Both are done via the Graph API, which is trivial enough with a bit of command line foo courtesy of the curl command.

# Step one retrieves an access token:

curl -F grant_type=client_credentials \
 -F client_id=APP_ID \
 -F client_secret=APP_SECRET \

This will spit back the access token - you can capture that into a text file by appending

"> access_token.txt"

to the end of the line.

# Step 2 creates a user, and captures their detail into a JSON file:

curl -F installed=true \
 -F permissions=read_stream \
 -F access_token="APP_ACCESS_TOKEN" \ \
> test_user.json

# Once you’ve created users, you can retrieve a list of them:

curl --request GET"APP_ACCESS_TOKEN"

# Test users can log in using the URL that’s supplied in the list:$USER_ID$&n=$TOKEN$

However, there’s a gotcha here - that URL is only valid for one login. Once it’s expired, you’ll need to recreate that URL by retrieving the list of users again.

# Accounts can be deleted using their access token:

curl --request DELETE \ \

Although it’s not specified in the docs, you’ll need to wrap the access tokens in quotes as they sometimes include dash characters, which confuses Curl.