A test user is a special user account, invisible to "normal" users, which is created on behalf of an app for the purpose of testing that app's Facebook integration. You can use test users for manual or automated testing. Each app can create up to 2000 test users.
We allow you to access the test account via a login_url
which allows you to directly log in to the account. The login_url
expires on first use or after one hour whichever happens first, but you easily refresh it to get a new login_url
for the same test user. We also provide you a user access_token
for each test user, so that you can take actions on their behalf via the Graph API.
In addition to the Graph API functionality described below for managing test users programmatically, there is also a simple GUI in the App Dashboard, available at Settings->Developer Roles as shown in the screenshot below. It exposes all of the API functions described in this document.
You can create a test user associated with a particular app using the Graph API with your app access token.
API
https://graph.facebook.com/APP_ID/accounts/test-users? installed=true &name;=FULL_NAME &locale;=en_US &permissions;=read_stream &method;=post &access;_token=APP_ACCESS_TOKEN
Parameters:
You can specify whether this user has already installed your app as well as the set of permissions that your app is granted for this user by default upon creation.
installed
: This is a Boolean parameter to specify whether your app should be installed for the test user at the time of creation. It is true
by default.
name
: This is an optional string parameter. You can specify a name for the test user you create. The specified name will also be used in the email address assigned to the test user.
locale
: This is an optional string parameter. You can specify a locale for the test user you create, the default is en_US. The list of supported locales is available as an XML file.
permissions
: This is a comma-separated list of extended permissions. Your app is granted these permissions for the new test user if installed
is true
.
access_token
: This is an app access token.
Response :
{ "id": "1234...", "access_token":"1234567..." , "login_url":"https://www.facebook.com/platform/test_account..." "email": "example...@tfbnw.net", "password": "1234..." }
id
: User id of the test user
access_token
: You can use this access token to make API calls on behalf of the test user. This is available only if your app has been installed by the test user.
login_url
: You can login as the test user by going to this url. This expires on first use or after one hour whichever happens first to ensure that the test accounts remain secure. You can easily refresh the login_url by simply calling the get method again.
email
: If logging in manually (that is, not using the login_url), you can use this as the user's email address.
password
: If logging in manually (that is, not using the login_url), you can use this as the user's password. You should store this password, as it will only be returned on the creation of the test user. This is because we don't store the password ourselves, just the hash. See this section should you need to change/reset the password.
Error Codes:
If you exceed the limit of test users you can create for an app you will receive an error.
Error code: 2900 (Too many test accounts)
You can add existing test users to other apps by using the Graph API with the app access token that you're adding the user to.
https://graph.facebook.com/APP_ID/accounts/test-users? installed=true &permissions;=read_stream &uid;=TEST_USER_ID &owner;_access_token=APP_ACCESS_TOKEN_OWNER &access;_token=APP_ACCESS_TOKEN &method;=post
Parameters:
uid
: User id of the existing test user
owner_access_token
: App access token of the app used to create the test user
You can access the test users associated with an app by making a GET
request to the Graph API with the app access token.
API
https://graph.facebook.com/APP_ID/accounts/test-users? access_token=APP_ACCESS_TOKEN
Response:
{ "data" [ { "id": "1231....", "access_token":"1223134..." , "login_url":"https://www.facebook.com/platform/test_account.." } { "id": "1231....", "access_token":"1223134..." , "login_url":"https://www.facebook.com/platform/test_account.." } ] }
id
: User id of the test user
access_token
: You can use this access token to make API calls on behalf of the test user. This is available only if your app has been installed by the test user.
login_url
: You can login as the test user by going to this url. This expires on first use or after one hour whichever happens first.
You can use the API to make friends connections for a test user with other test users of that app. We provide an API for creating a friend request as well as for accepting a friend request. This enables developers to create several friend connections between test users via the API itself, without having to log-in as the test user to accept requests.
API
https://graph.facebook.com/TEST_USER_1_ID/friends/TEST_USER_2_ID? method=post &access;_token=TEST_USER_1_ACCESS_TOKEN https://graph.facebook.com/TEST_USER_2_ID/friends/TEST_USER_1_ID? method=post &access;_token=TEST_USER_2_ACCESS_TOKEN
Response: true
on success, false
otherwise
You can change a test user's password by simply issuing a POST
request with a password
parameter to the test user ID in the Graph API.
API
https://graph.facebook.com/TEST_USER_ID? password=NEW_PASSWORD &name;=NEW_NAME &method;=post &access;_token=APP_ACCESS_TOKEN
Parameters:
password
and name
: both optional parameters. This request can be used to change the name and/or password of an existing test user.
Response: true
on success, false
otherwise
You can delete an existing test user like any other object in the graph.
API
https://graph.facebook.com/TEST_USER_ID? method=delete &access;_token=TEST_USER_ACCESS_TOKEN (OR) APP_ACCESS_TOKEN
Response: true
on success, false
otherwise
Error Codes:
API_EC_TEST_ACCOUNTS_CANT_DELETE (2903)
: Test user is associated with multiple apps.
API_EC_TEST_ACCOUNTS_CANT_REMOVE_APP (2902)
: Test user must be associated with at least one app.
API_EC_TEST_ACCOUNTS_INVALID_ID (2901)
: Test user is not associated with this app.
We ensure that test users are exempt from Facebook spam or fake account detection systems to ensure that you can test your app without worrying about getting disabled.
Also, to ensure that using test user accounts to test various scenarios doesn't end up unintentionally creating spam, we enforce certain limitations on what test users can do.
We have created a special test user on your behalf called Open Graph Test User.
When our review team reviews your submission for an Open Graph action, we test with this user. Therefore, before submitting, it is important to ensure that this user can successfully access your app and publish the action to their timeline, as outlined in your usage instructions. If your test user requires friends to perform the action please be sure to set up your test user with friends.
You can access this test user by navigating to Developer Roles, within your app settings.