Home > Facebook SDK > New way to create test users in Facebook

New way to create test users in Facebook

Introduction

As mentioned in the Facebook developer docs, test users can only be created using a call to the Graph API.
As described in my previous Facebook article, a dedicated webpage was available at the time to create test users, however, that page has been brought offline. 

You can create a test user associated with a particular app using the Graph API with your app access token.


https://graph.facebook.com/APP_ID/accounts/test-users?

  installed=true
  &permissions=read_stream
  &method=post
  &access_token=APP_ACCESS_TOKEN

However, before we’ll be able call this API, we first need to retrieve an Access Token for our application.

Application Access Token

Before you get started, you might want to startup a text editor to copy paste some of these URLs and values (application ID, application secret, access token) as you’ll need to construct a lot of URLS that include these values.

In order to get an Access Token for our application, we need to know our Application Secret.

The first thing we’ll need is our Facebook Application ID. The Application ID is a unique identifier that you received while creating your application.
We’ can use the URL below to retrieve our Application Secret. Fill in your Application ID in the following URL to goto your Facebook App page and retrieve the Application Secret.

http://www.facebook.com/developers/editapp.php?app_id=YOUR_APP_ID

Now that we have the Application ID and the Application Secret, we can retrieve an access token for our application. In order to do that, we need to call the following URL with our Application ID and Application Secret.


https://graph.facebook.com/oauth/access_token?

	client_id=YOUR_APP_ID
	&client_secret=YOUR_APP_SECRET
	&grant_type=client_credentials

You’ll receive the following response:

access_token=109688035775165|hZe8qX8el6Qlp0xMyoAb5giYRls

Creating the test user

Now that we have our access token, we can do the task at hand, and use the Graph API to call our test-user.


https://graph.facebook.com/APP_ID/accounts/test-users?

  installed=true
  &permissions=read_stream
  &method=post
  &access_token=APP_ACCESS_TOKEN

With everything filled in, your request should look resemble something like this:

https://graph.facebook.com/109636235495125/accounts/test-users?installed=true&permissions=read_stream&method=post&access_token=109636235495125|qZe8yX8eL6zlp0xMGoAj5girRlS

If all went well, you should get a response similar to this:

{
   "id": "10000123432213",
   "access_token": "109636235495125|2.DFDGayE7X1s9ft_N7k94_E__.3600.1304802000.0-100002332671439|HhwACDVFeNhQ_UV0tQY0mUzkvLs",
   "login_url": "https://www.facebook.com/platform/test_account_login.php?user_id=10000123432213&n=R3feV4O7YrlIb0n",
   "email": "some_one\u0040tfbnw.net",
   "password": "3123123123133"
}

This basically means your test user has been created, and you can login to Facebook with this account. Use the email address (some_one@tfbnw.net) to login, and the password provided in the response.

You can change the password to a more convenient value for testing.

References

Bookmark and Share
Categories: Facebook SDK Tags: ,
  1. ramesh
    September 26th, 2011 at 09:53 | #1

    what you mean by accesstoken in facebook

  2. Paul
    December 8th, 2011 at 03:45 | #2

    Hi, thanks for the post/tutorial. I followed the steps and at the end I got a response like the one you you said should be received but I cannot log in with it. Thanks for any input

  3. willy
    February 27th, 2012 at 02:21 | #3

    Thanks for this tutorial. I could create a test user, but I couldn’t login with Android. Is there any trick to do that? Thanks again

  1. No trackbacks yet.