Tuesday, February 22, 2011

Creating facebook test user account for testing your facebook application

If you are developing some Facebook application then you will need to test it with different user accounts. You will even need network of user account meaning accounts with friends. You would not like to do the testing with your real Facebook account because while testing you might be posting lot of junk data to your wall and this will get published to your friends news feed. You even might require adding new friend and removing friends for the testing purpose.
One option is to create fake accounts. But this is not clean way of doing. You will have to create so many fake email account and you will have to fill lot of fake user info. And another thing is that Facebook deletes fake account once they find it as fake.
There is other clean way of doing. Facebook provide API to create test accounts. These accounts will not be deleted by Facebook. Unfortunately Facebook currently does not provide any GUI to create test account. You will have to use Facebook API to achieve this. 
Here are the things that will be required to achieve this:-
1) A web browser (preferably firefox, I have not tested it on other browsers)
2) wget command line utility. This is freely available and most of the Linux distro has this by default. ( other tools like curl can be used but I am describing here with the help of wget). The reason we use wget is that we need HTTP post method.

Step 1: Get the application access token.
Type this URL in web browser.
https://graph.facebook.com/oauth/access_token?client_id=XXXXXX&client_secret=XXXXXX&grant_type=client_credentials

Replace XXXXX appropriately with your app ID and app secret.

This will give you access token. In the browser you see content like
access_token=XXXXX
Please note down this access token.

Step 2: Create test accounts.
We will need wget command line utility for this. Run this command line utility to create a test user
wget --post-data "installed=true&permissions=read_stream&access_token=TOKEN" https://graph.facebook.com/APP_ID/accounts/test-users
Replace TOKEN with what you got in the step 1 as access token and replace APP_ID with your Facebook application id.
Run this command as many times as many users you want to create.

Step 3: Get the login URL for each users:
Type this URL in you browser
https://graph.facebook.com/APP_ID/accounts/test-users?access_token=TOKEN
Replace TOKEN with what you got as access_token in step 1 and replace APP_ID with your Facebook application ID.

This will give you Info for each test account created. The info also contains login URL. Copy and paste the URL in browser to login into the test user account.

Few more things:
- The login URL is valid for one session only. You will have to repeat the step 3 to get new login URL.
- Access token is gets expired after some time. repeat the step 1 to get fresh access token.
-  Refer the facebook documentation here for more detail
http://developers.facebook.com/docs/test_users/



6 comments:

  1. Just what I was looking for. Thanks!

    ReplyDelete
  2. Hey, thanks for this. Unfortunately for the life of me I cannot figure out how to make these test users friends with each other, I keep getting error:400 bad request and I think guessing is just getting me further from the right answer.
    Would you be able to show me the way?

    Thanks

    ReplyDelete
  3. Exaclty at which step you are getting this error. I hope You have successfully created test users.. right?

    ReplyDelete
  4. Yep, can make test users fine but the fb documentation for making them friends (I want to test the getAppUsers query) doesnt show how to to do so with wget. As I can't search for each friend throuhg fb. Any ideas?

    Thanks

    ReplyDelete
  5. A test user can not view real users profile and vice-versa. From the profile of a test user, visit the profile of other test user and send friend request as you do with real user. Then login with the account of other test user and accept the friend request.

    ReplyDelete
  6. Hi All,
    Whatever described here is some how correct but preferably that's not an efficient way of testing your application. You can download many other application for the purpose.

    ReplyDelete