Adoption Curve Dot Net

Creating and Using Test Facebook Accounts

| Comments

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 \
 https://graph.facebook.com/oauth/access_token

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" \
 https://graph.facebook.com/APP_ID/accounts/test-users \
> test_user.json

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

curl --request GET https://graph.facebook.com/APP_ID/accounts/test-users?access_token="APP_ACCESS_TOKEN"

Test users can log in using the URL that’s supplied in the list:

https://www.facebook.com/platform/test_account_login.php?user_id=$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 \
 https://graph.facebook.com/ \
 ?access_token="USER_ACCESS_TOKEN"

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.

Comments