Graph API Version

Graph API Reference /{app-id}/accounts/test-users

The test users associated with this app.

Related Guides

Reading

Graph API Explorer
GET /v2.11/{app-id}/accounts/test-users HTTP/1.1
Host: graph.facebook.com
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->get(
    '/{app-id}/accounts/test-users',
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/accounts/test-users",
    null,
    HttpMethod.GET,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/accounts/test-users"
                                      parameters:params
                                      HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

Permissions

  • An app access token for the app in the request is required.

Fields

NameDescriptionType

id

The user ID of the test user.

string

access_token

The access token for the test user and this app. This field is only visible if the test user has installed the app.

string

login_url

This URL will allow the test user account to be logged into. The URL will expire one hour after it is generated, or after the first time it is used.

string

Publishing

By publishing using this edge, you can create new test users and you can assosciate existing test users with new apps.

POST /v2.11/{app-id}/accounts/test-users HTTP/1.1
Host: graph.facebook.com

installed=true
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post(
    '/{app-id}/accounts/test-users',
    array (
      'installed' => 'true',
    ),
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
Bundle params = new Bundle();
params.putString("installed", "true");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/accounts/test-users",
    params,
    HttpMethod.POST,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
NSDictionary *params = @{
  @"installed": @"true",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/accounts/test-users"
                                      parameters:params
                                      HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

Permissions

  • An app access token is required to create new test users for that app.
  • If associating existing test users with new apps, app access tokens are required for both the app that created the test user, and the app that is being newly associated to the test user (see owner_access_token for more).

Fields

NameDescriptionType

installed

Automatically installs the app for the test user once it is created or associated.

boolean

permissions

List of permissions that are automatically granted for the app when it is created or associated.

string

name

The name for the test user. When left blank, a random name will be automatically generated.

string

owner_access_token

When associating existing test users with other apps, this is the app access token of any app that is already associated with the test user. The {app-id} in the publishing request in this case should be the app that will is the target to associate with the test user. The API request should also be signed with the app access token of that target app. Required when associating test users, but should not be used when creating new test users.

string

uid

ID of an existing test user to associate with another app. Required when associating test users, but should not be used when creating new test users.

string

Response

When a test user is successfully created or associated the following will be returned, otherwise an error message will be shown:

Name Description Type

id

The new test user ID

string

access_token

The access token belonging to the test user. Only included when the test user has installed as true.

string

login_url

This URL will allow the test user account to be logged into. The URL will expire one hour after it is generated, or after the first time it is used.

string

email

The test user's email address.

string

password

The test user's password.

string

Deleting

You can't delete a test user using this edge, however you can delete a test user using the /{test-user-id} node.

When deleting using this edge, you can disassociate a test user from an app:

DELETE /v2.11/{app-id}/accounts/test-users HTTP/1.1
Host: graph.facebook.com

uid=12345678
/* PHP SDK v5.0.0 */
/* make the API call */
try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->delete(
    '/{app-id}/accounts/test-users',
    array (
      'uid' => '12345678',
    ),
    '{access-token}'
  );
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();
/* handle the result */
Bundle params = new Bundle();
params.putString("uid", "12345678");
/* make the API call */
new GraphRequest(
    AccessToken.getCurrentAccessToken(),
    "/{app-id}/accounts/test-users",
    params,
    HttpMethod.DELETE,
    new GraphRequest.Callback() {
        public void onCompleted(GraphResponse response) {
            /* handle the result */
        }
    }
).executeAsync();
// For more complex open graph stories, use `FBSDKShareAPI`
// with `FBSDKShareOpenGraphContent`
NSDictionary *params = @{
  @"uid": @"12345678",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                               initWithGraphPath:@"/{app-id}/accounts/test-users"
                                      parameters:params
                                      HTTPMethod:@"DELETE"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                      id result,
                                      NSError *error) {
    // Handle the result
}];

Permissions

  • The associated app access token is required to disassociate a test user.
  • A test user must still be associated with any single app after this operation, otherwise an error message (2902) will be shown.

Fields

NameDescriptionType

uid

The ID of the test user to be disassociated from the app.

string

Response

If successful:

{
  "success": true
}

Otherwise a relevant error message will be returned.

Updating

You can't update a test user using this edge, however you can update a test user using the /{test-user-id} node.