Please enable Javascript to view this site.
 
 
  • Coding

  • Technology

  • Japanese

  • Chinese

  • Miscellaneous

Automating Facebook

January 27, 2009 | Tags: | Leave a comment

Some of the facebook applications out there require the user to click “submit” buttons (or other action buttons) a certain number of times every day. Examples include racing applications (“click to race” buttons), fluff friends (“click to pet” buttons), and others. It might be fun in the beginning to do the clicking yourself and see the results first hand, but eventually it gets old, even if the benefits received from clicking are still desirable. Thus, it would be nice to create a script that does the clicking for you, so that you still receive the benefits while not wasting time mindlessly clicking a silly button.

The topics discussed here require a bit of HTML, PHP, and Javascript knowledge, but most of that can be gleaned from sites like w3schools and, of course, Google.

Strategy

This page provides a general outline with some code examples, and is not meant to be copied word for word. These scripts will vary according to the type of application and interaction you’re trying to automate. So keep an open mind to other methods and options. Also, this is just a very simple framework meant to help people get started. Some may find the info here blazingly obvious.

The strategy here is to (1) discover what makes the “submit” button on the facebook application page work, (2) duplicate that form on a private server with a script that dynamically creates a form for each input variable combination, (3) have that script automatically invoke a Javascript submit action for each form.

Deciphering Facebook Forms

View the source of the Facebook page where you normally click the “submit” button and look for the <form> element that contains the <input type=”submit”> tag that creates your “submit” button. The elements in that form that you’ll need to pay attention to are the following:

  • <form action = “[path_to_facebook_page]“>
  • <form id=”[string_containing_name_of_app]“> (not always necessary)
  • <input name=”fb_sig_time” type=”hidden”>
  • <input name=”fb_sig_user” type=”hidden”>
  • <input name=”fb_sig_session_key” type=”hidden”>
  • <input name=”fb_sig_api_key” type=”hidden”>
  • <input name=”[anything_related_to_application_interactions]” type=”hidden”>
  • <input type=”submit”>

The form action is the page called by the app when the “submit” button is clicked. Note that Facebook uses clean URLs, so don’t worry if you don’t see a file extension for this value.

The form id isn’t always there, but some apps use it to identify the form, so if you see it, make sure you copy it over to your script.

The input fb_sig_time is just a timestamp with a 4 (or fewer) digit number appended to the end with a dot. The best way to fake this is with <?php time() . ‘.’ . rand(1,9999); ?>

The input fb_sig_user is your Facebook profile ID. Just copy it over.

The input fb_sig_session_key is used to keep track of your session. It’s best to include this and make sure you’ve already logged into Facebook with the “remember me” option checked.

The input fb_sig_api_key is related to the Facebook application APIs, and it’s probably a good idea to keep that in the form.

Next are any number of input elements related to the application in question. If it’s an application that involves competing with friends in some manner, you’ll probably see your friend’s profile ID in here. If it’s an application that involves choosing between different actions, look for an element that defines those choices. When in doubt, copy everything over to your script to be safe. In the script example later down this page, I use the variable appvars to hold/pass these element values.

The input submit button is, naturally, the “submit” button. Make sure you copy over the same id and name fields.

Creating the Script

The skeleton of the form should be pretty much fixed according to the elements described in the previous section. The only dynamic parts are profile IDs, the timestamp, and any application specific input elements that vary for each form. The easiest way to handle multiple forms is to create two PHP/Javascript files

  • launcher.php: Use this to store arrays of variables for each profile ID and app choices you want to include, then pass these variables to the appform.php script. We’ll be using setInterval() to do the repeated calls.
  • appform.php: Use this to generate the forms. Use <?php echo $var; ?> where appropriate in your form fields. We’ll be using document.forms[i].submit() with setTimeout() to have the script automatically submit the form for us.

For example, my launcher.php script contains the following:

<script>
// Array below stores options for each form variable.   One form will be created for each option.
// If there are multiple options for each form, use a  multidimensional array.
var appvars = new Array([list_of_options_for_each_form]);
var i = 0;

// This function starts the recurring calls to  callAppForm(), set to execute every 20 seconds.
function startInterval() {
// Since the first call from setInterval() is  delayed,
// we do a preliminary call here because we're  impatient.
callAppForm();

// 20000 here is milliseconds, so that's 20  seconds between each call.
intervalID = setInterval("callAppForm", 20000);
}

// This function calls the appform.php script
function callAppForm() {
// Terminate when all appvars have been  executed, and provide a final status update.
if (i >= appvars.length) {
clearInterval(intervalID);
document.getElementById(updates).innerHTML='Finished '+i+'/'+appvars.length+'!';
i = 0;
return;
}

item0 = '?item0='  + appvar[i][0];
item1 = '&amp;item1='  + appvar[i][1];
item2 = '&amp;item2='  + appvar[i][2];   //  et cetera...
appformurl = 'appform.php'  + item0 + item1 + item2 ....

// Write status updates to the HTML document.
document.getElementById(updates).innerHTML  = 'Processing'+(i+1)+'/'+appvars.length+'...';

// Open the appform script in a new window.
window.open(appformurl, windowID);

i++;
}
</script>

<a href="#" onclick="startInterval()">Click  me to start the process</a><br  />;
<span id="updates">Idle.</span>;

Then, in my appform.php script, I have the following:

<?php
$profileID = $_GET[profileID];
$fb_sig_user = $_GET[fb_sig_user];
$fb_sig_time = time()  . '.' . rand(594,8877);
header('Referer: http://apps.facebook.com');
?>
<form ...>
<!-- All those input elements described earlier go here -->;
<input name="fb_sig_user" value="<? echo $fb_sig_user; ?>" type="hidden">
<!-- et cetera, including the submit button -->;
</form>;

<script>
// I use a delay here before submitting the form so I can review it.
// forms[0] will refer to the first form in your page, form[1] the  second, etc.
// For some reason, document.elementID.submit() wouldn't work for me.
setTimeout("document.forms[0].submit()", 5000);
</script>

Now with this setup, whenever you click the link at the bottom of the launcher.php script, it’ll launch the entire cycle of creating forms and submitting them to Facebook until the limits of appvars[] is reached. Of course, if you want to completely automate this, change:

<a  href="#" onclick="startInterval()">

to

<body  onload="startInterval()">

and add launcher.php to a cron job (UNIX) or scheduled task (Windows).

Final Thoughts

In summary, the launcher.php script is in charge of the multiple calls to appform.php, which in turn fires off one submit action for each call. By modifying launcher.php, you can even include multiple applications and multiple users as the base for each run. You might have to create a new appform.php script for different applications. For multiple user accounts that you control, configure launcher.php to send different userIDs to appform.php, and make sure appform.php inserts those userIDs into the forms where appropriate. Also, you’ll want to launch the script for each different user from a browser that has a cookie for that user’s session.

Finally, some people may think this is a dirty trick to play on the app and that it takes away from their ad revenue. First of all, if you’re geeky enough to implement this, you probably already have adblock, a modified hosts file, or some other means of blocking ads anyway. Also, the monotonous clicking required by some applications is enough to discourage people from using the app entirely, and if this shortcut can keep them interested in the app for a little longer, then I think it’s a good thing.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.