• Managing Test Users in Facebook

    by  • February 7, 2011 • PHP, Tools • 5 Comments

    Recently Facebook implemented a new and more secure way of creating test users for your applications using the new Graph API. This new resource creates test users per application, allowing the developers of these apps to login as these users and test out their app’s functionality without using their own accounts and throwing test information into their live activity feed, this makes it very easy and clean to test new applications.

    Its possible to create up to 100 test users per app, creation allows you to choose whether the user already should have the application installed and which permissions you want them to have, using API calls like:

    POST /app_id/accounts/test-users?installed=true&permissions=read_stream

    You can also remove users, list all of your app’s test users and even create friend connections between them using the API. This really is a great resource, but using an API to get this information all the time is cumbersome and might take time away from your time to develop the application itself.

    This is where the Test User Manager comes in.

    Having ran into this exact issue when developing for Facebook, I wished i could have a “phpMyAdmin”-like application to handle these requests for me and just give me a simple interface to work with. That’s when the idea was born an i decided to use the idea and opportunity to simplify my life and also learn/research a few other libraries and such.

    I decided to create a very simple app, without a large MVC framework, just a bunch of actions. I also took the opportunity to use a simple template engine to see how it behaves, so i chose Twig for this. Since i did not have the comfort of large MVC framework to handle my requests, i also decided to look at funkatron’s Inspekt library to handle input security. Since i did not want to go through some troubles I also imported a limited set of tools from Zend Framework to handle autoloading and smaller tasks. Also having not worked with front-end too much in a while I took hold of jQuery and a few plugins to see what they could do.

    All in all i had a very simple but effective app. Right now (version 0.9) it does the basics, add, lists, deletes and creates relationships between Test Users. But it handles exactly the most boring and annoying tasks. Let me show you a bit:

    Listing/Managing Users

    Screenshot of App

    Test User Manager for Facebook: List/Manage Users

    The user list will show you all of your test users, their IDs, name and permissions. With the command icons you can see the access_token, login on Facebook as the user, delete him or add new friends. Since this is a API heavy process to get all information loading is done in parallel using ajax.

    Creating a User

    Screenshot of adding user

    Test User Manager for Facebook: Add user

    The for to add new users is straight forward, you can add permissions and decide if the app will be installed or not for the user.

    Viewing and Creating relationships

    Screenshot od add/view friends

    Test User Manager for Facebook: Add/View Friends

    Clicking on the “add friend” icon you can view a list of existing relationships and choose a new user to associate with this user.

    All the source code for this application is on GitHub, feel free to open feature requests and bug reports and of course pull requests at will. I hope this app can help you as a Facebook developer and make everyday life easier.

    Download version 0.9 here

    About

    Rafael Dohms is an experienced PHP Developer, Evangelist, Speaker and Contributor. During his years of experience he has become an active member of the community and founded 3 User Groups. He moved to the Netherlands to integrate the WEBclusive team and share his passion for code quality and innovation in the Crowd funding world. In his spare time he also helps manage the AmsterdamPHP User Group, amongst other projects.

    http://doh.ms

    5 Responses to Managing Test Users in Facebook

    1. Pingback: Tweets that mention Managing Test Users in Facebook « Rafael Dohms -- Topsy.com

    2. Pingback: Tweets that mention Managing Test Users in Facebook « Rafael Dohms -- Topsy.com

    3. Pingback: Tweets that mention Managing Test Users in Facebook « Rafael Dohms -- Topsy.com

    4. February 7, 2011 at 16:32

      Haven't tried this yet, but I will – you are a damned genius, thank you!

      • Rafael Dohms
        February 8, 2011 at 8:38

        Hope it helps, it made my life much easier

    5. Mucky
      February 7, 2011 at 21:20

      Sounds great… i will definitly check this out!

    6. Terence
      February 11, 2011 at 0:05

      I met following warnings, and it cannot remove user, display tester detail information.
      Thanks a lot.

      PHP Warning: array_filter() expects parameter 1 to be array, null given in C:Program FilesEasyPHP-5.3.3.1wwwtestuserMgrlibraryAppActionAjaxUserinfoAction.php on line 26

      PHP Warning: array_keys() expects parameter 1 to be array, null given in C:Program FilesEasyPHP-5.3.3.1wwwtestuserMgrlibraryAppActionAjaxUserinfoAction.php on line 26

      PHP Warning: implode() [function.implode]: Invalid arguments passed in C:Program FilesEasyPHP-5.3.3.1wwwtestuserMgrlibraryAppActionAjaxUserinfoAction.php on line 26

      • Rafael Dohms
        February 11, 2011 at 10:35

        Terence,I'm opening an issue on GitHub to look at this.If you can provide anymore details it would be great also.

    7. Alex
      February 17, 2011 at 16:18

      The application is a great idea. One problem thought, the Ajax component that pulls the user detail seems to fail on any browser I try (IE, Chrome, Safari). I've debugged it a bit. The Ajax calls suceeds, but the loading layer is never hidden and the data is never loaded (even thought those lines of codes do seem to execute). There are no errors in the console.

      • Rafael Dohms
        February 17, 2011 at 16:42

        Alex,I would need to access your app to figure this out. I was unable to reproduce this locally.

        • Alex
          February 17, 2011 at 17:35

          It's complicated since we are running the app on our local network. I'll look into setting up a separate version.

          Btw, what browser do you use? Anything I should be on the lookout for?

    8. Alex
      February 17, 2011 at 17:45

      I would need permission to check on that. Let me back to you on that. Is there a more private way to communicate?

      • Alex
        February 17, 2011 at 17:55

        I've sent some info via the contact form of your website. Cheers, and thanks for the help.

    9. Bruno
      February 22, 2011 at 14:59

      I installed apache and php5 and when I tried to lunch the program it appear this:

      Fatal error: Uncaught exception 'Exception' with message 'Facebook needs the CURL PHP extension

      And i don know how to solve. Can you help me?'
      Thanks !!

    10. Bruno
      February 28, 2011 at 10:18

      Thanks Rafael. Now I can see the main page of Facebook Test User but i have an other problem:

      connect() timed out!.

      I edit the config.ini.php

      <?php
      define('FACEBOOK_APP_ID', '19639440370####');
      define('FACEBOOK_APP_SECRET','###59a798ab8a#####8d0##dcf#b#dde');

      What I'm doing wrong ?.
      Thaks a lot !

      • Rafael Dohms
        February 28, 2011 at 18:14

        Could you please send me more information about the error? the complete message, line, file etc…

        Could be that the API is down or something?

        • Bruno
          March 1, 2011 at 15:17

          The complete message is: connect() timed out!

          line 44: <p class="error_msg">connect() timed out!

          File: layout.html.

    11. Dave
      March 1, 2011 at 5:06

      thanks this is exactly what I was looking for as Im building an iPhone app using the facebook SDK and am not very familiar with scripting/php on the web.

      Sorry seriously newbie web-dev question but do I just need to copy this across to a directory on a web server in order to run (I did this but am getting a '403 forbidden' message on my Apache server when I hit the folder URL) or is there some type of installation process that Im missing? Thanks again – once I get this working it will be a real time saver (dont know why FB havent built this to be honest).

      • Rafael Dohms
        March 1, 2011 at 10:20

        @DaveThe 403 might be an indication of folder permissions and the apache user. But other then that you just need to enable the mod_rewrite module, and set AllowOveride to All or similar, and of course, have PHP available.All of this is pretty well documented around the web, a google query on each should get you up to speed.

    12. filip mertens
      March 11, 2011 at 12:40

      this is great!!!! thanks a million!!!

      • Rafael Dohms
        March 11, 2011 at 12:54

        You are welcome, let me know if you find any bugs or need any new features

    13. Eric
      March 28, 2011 at 13:11

      I am getting the following message: "SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" What would this be caused from?

      • Eric
        March 28, 2011 at 13:14

        Turns out I was able to figure this out… Within the facebook.php file I needed to add the following lines to the $CURL_OPTS array:

        CURLOPT_SSL_VERIFYPEER => false,

        • June 7, 2011 at 3:31

          I had the same error and after a google search came up with this fix (instead of disabling the verification):

          1. download mozila.pam file. See this page for more info: http://davidwalsh.name/php-ssl-curl-error
          2. copy file to C:WINDOWSsystem32
          3. Add this to $CURL_OPTS array in facebook.php:
          CURLOPT_CAINFO => 'C:WINDOWSsystem32mozilla.pem'

    14. Pingback: Facebook test users follow-up « Pavel Langweil's blog

    15. Christopher
      April 7, 2011 at 17:11

      Hey Rafael,

      Thanks for posting this stuff to Github, I'm going to download and give it a try.

      Here's a question related to test users… Do you have any idea of a way, when using a test user on your application, to have the test user identify itself as a tester?

      I'm trying to create accurate statistics for an application, and the large number of test users I use is undoubtedly throwing things off.

      Thanks for anyone who has an idea!

      Christopher

    16. Bruno
      April 15, 2011 at 9:11

      Hi..
      I got the error 500 on a shared host..
      details:
      Internal Server Error
      The server encountered an internal error or misconfiguration and was unable to complete your request.

      can you please help me how to solve it.?

      thanks

      • Rafael Dohms
        April 15, 2011 at 9:48

        Bruno,Please look at you Apache error log. I would suspect you might not have mod_rewrite enabled or your AllowOverride settings are set to None.

    17. April 27, 2011 at 1:19

      hi, this is very helpful app. i have one test users hanging, cannot delete but can see user's fb account. how to force delete? thanks a lot.

    18. April 28, 2011 at 7:17

      Gotcha!! yes, indeed it works!
      infact, after installing the app, why remove :P
      You're superb! I should hire you next time.

    19. mafi
      April 29, 2011 at 6:34

      This is a great tool!

      One question: I presume that one needs to browse to the "/public" folder? If I do so, I get an error saying

      Warning: Unexpected character in input: '' (ASCII=92) state=1 in public/index.php on line 5
      Parse error: syntax error, unexpected T_STRING in public/index.php on line 5

      Dunno what I'm doing wrong here… :-P Can you help?

      • Rafael Dohms
        April 29, 2011 at 8:35

        Do you have PHP 5.3? that looks like the error you usually get with namespaces in PHP 5.2 that does not support them.

    20. May 23, 2011 at 14:06

      Nice tool. If you prefer command line type of things, check out Geppetto http://ternarylabs.com/2011/03/26/control-your-fa

    21. Taj
      May 31, 2011 at 12:46

      If you have problems with the app, make sure that you have:

      - support for .htaccess files
      - apache mod_rewrite is enabled
      - running on PHP5
      - installed PHP5 cURL extension
      - installed a cURL certificate that enables HTTPS transfer via cURL

      If above conditions are true, the app works like a charm :)

      Thanks for the tool, I was just about to write one myself and now I don't have to. Yay!

      • Rafael Dohms
        May 31, 2011 at 13:00

        thanks for the requirements, will update the README file with more details.Glad it helps.

    22. Pingback: FireLike » Managing Test Users in Facebook

    23. August 26, 2011 at 8:15

      Great tool! Makes it all very simple. Good job.

    24. August 6, 2012 at 13:17

      I am planning to make Facebook Applications.But,need to learn most of the things.I just browsing your blog & found this post.It help me in some process of my development.Thanks!

    Leave a Reply