Hey there, I'm Tyler. This is my blog.

Tools for Using Facebook as a Sociological Method

Posted on 03 Aug 2012

Here you’ll find tools to collect sociologically relevant data from users on Facebook. I’ve noticed that a lot of research in sociology pays attention to the social impacts of Facebook and other social networking sites. While they are usually really interesting, especially when they focus on things like identity, public and private politics and increased social mediation, they are usually only taking evidence from the offline surface of Facebook, as mediated through the accounts of their subjects.

While I was doing my research into social media networks, I was looking for ways to get more direct access to the social reality of Facebook. Instead of trying to find a sociology of Facebook, I was particularly looking to find a sociology in Facebook. After investigating the tools and methods that were available I’ve developed a resource for sociologists interested in doing social research in Facebook rather than around it. While the methods do utilize programming code, I’ve developed a number of packages that people without any programming knowledge can use to gather data.

There are two major methods that can be employed to gather data from Facebook users:

  1. Collecting information from publicly available profiles.
  2. Developing Facebook applications to either gather user information or solicit subject responses.

There are obvious limitations to the first method, as the demographics tend to skew towards older and more public professional profiles. There are some unique findings that can come out of that method, however. For instance, when we were interested in knowing how often people talked about their ‘needs’, we were able to to collect wall posts mentioning specific phrases from millions of users.

The second approach limits your sample size to the number of individuals whom are willing to access your Facebook application, but you gain richer data from the user and are able to control more for sample bias. To get a general idea of the information available for each user check out the Facebook permissions page. It’s a long list but you’ll get the idea. Now onward to the actual methods:

Collecting information from public profiles.

The basic process for collecting public info is:

  1. Create a Facebook application and host for the app.
  2. Perform queries against Facebook database.
  3. Load results into database of choice (R, SPSS, Excel, etc.).

There are a number of great examples about creating Facebook applications, but I’ll simplify the process as it relates to purely data-gathering purposes. First things first, you need to have a Facebook account. If you don’t have one, go to Facebook and set one up. Next you’ll need to have a place to host the application online. Your university likely gives you a place for a website, so you should check with your university’s IT department about how to access that. If not, you can always set up a hosting account from a number of companies for free. I use an amazon ec2 instance, but a quick google search will give you a number of companies that offer free hosting. You should make sure that it is capable of running php scripts. Most likely if it’s on a university server it should have php installed.

Now, you need to create a Facebook application profile. To do this, go to http://www.facebook.com/developers/ and click set up new app. It should ask you to add the Facebook Developer app. Occasionally it shows a 404 error page after you click allow. If so, just go back to http://www.facebook.com/developers/. Click, set up a new app. It may ask you to verify your account with a mobile phone or credit card. I’d choose mobile phone, since the idea of Facebook having my credit card number is eerily spooky. Follow the instructions and head back to http://www.facebook.com/developers/ when you’re done. You’ll give your app a name and see this screen when you’re at the main application setup page:

There are three fields that you will want to change:

  1. Site URL under the Website tab. This should be the location on your hosting service where you’ll put the application files. Mine is http://www.tylerhoran.com/blog/fbrsrchsample/ for example.
  2. Canvas Page under the Facebook Integration tab. This is the public URL that you will go to collect the data output from your Facebook queries. You can be creative with this one and create a new name.
  3. Canvas URL under the Facebook Integration tab. This should be the same as what you entered into the Site URL. In my case: http://www.tylerhoran.com/blog/fbrsrchsample/.

After you’ve made the changes click ‘Save Changes’ at the bottom of the screen. You’ll now see the application info page. Copy the ‘Application ID’ and ‘Application Secret’ string and save them somewhere handy. You’ll need it when we setup the files on your hosting server. Everything is now setup on the Facebook end. Next we need to put the data gathering files on your personal university webspace.

I’ve created a handy zip file that includes the files needed to run public queries which can be downloaded here. Unzip the files and open the file called index.php in a text editor (TextEdit works fine if you have a mac, as does Notepad if you have a PC). Replace APPLICATION_ID and APPLICATION_SECRET with the two strings that you saved from the previous step.

1
2
3
4
5
$facebook = new Facebook(array(
'appId' => 'APPLICATION_ID',
'secret' => 'APPLICATION_SECRET',
'cookie' => true,
));

Upload both of those files to the directory that you specified in the ‘Site URL’ and ‘Canvas URL’ fields above and you’re all set up. When you go to the Facebook application’s URL, after it loads you should get a comma separated list of the last 100 people who talked about watermelon with their user id, time of post, global location and gender. You can see the results on my sample application here.

So now, a bit about how to use this file to gather more pertinent information. Looking closer at the lines

1
2
3
$query = $facebook->api(
'/search?q=watermelon&type=post&fields=from&limit=100'
);

look for ‘q=watermelon’. This is the string that you are looking for. You can replace ‘watermelon’ with anything you’d like to find people talking about on Facebook. At the end of the string look for ‘limit=100’. You can change this to the max number of responses you’d like to find, but keep in mind that Facebook limits the number of requests you can make to 600 every ten minutes. Lastly, if you’re monitoring a specific topic at a specific time, you can limit the date/time range by adding ‘&since=2008&until=2009’ to the end of the line before ‘); and after limit=100. You can adjust the dates to your liking (eg. 2011-05-07). Below are a couple examples of what you can do with this:

  1. Track the volume, global distribution and gender bias of topics following large-scale political, economic, and social events.
  2. Compare the gender distribution of topics in various locales throughout the world.
  3. Monitor the volume of conversation of any given topic over time and by location.

Once you have the output of the data on your Facebook application screen, you can then go about importing it into your statistics program of choice as a comma separated data file. If you’re like me though, you want to get richer data from users on Facebook. To do this, we need to create a Facebook application that gathers a bit more information about the user.

Developing Data Gathering Facebook Applications

As sociologists and other social researchers, we’re all fairly familiar with survey methods. The design, implementation and analysis of the research tool are are just as important as the observations you gain during it’s administration. Working with a Facebook application, you can treat it just as you would any other survey or research tool. When you create a Facebook application, you can instruct anyone whom you chose to ‘play’ the application, while the Facebook application gathers ‘observations’ about the user. As the end result, you gain the results of the ‘survey’, whether those are questionnaire responses or scores from a game as well as detailed observations about the user. In our case, the observations will be the information about the user and their social network.

While creating a Facebook application sounds a bit daunting at first, it’s fairly simple even to those without programming knowledge. You can still use your favorite survey tools like surveymonkey or surveymethods to build your content and the output of the data will be in an easily accessible comma-separated text file.

The basic process for developing data gathering Facebook applications is:

  1. Create a Facebook application and host for the app.
  2. Create survey content for user to complete.
  3. Perform queries against Facebook database.
  4. Load results into database of choice (R, SPSS, Excel, etc.).

The first step in developing our Facebook application is the same as described above in gathering public information. After you’ve setup the application profile on Facebook and the appropriate directory for your files on your university server, we can start editing the content of the application. I’ve created another directory called http://www.tylerhoran.com/blog/fbrsrchsurvey/ to put our data collecting app files, but before we start editing the package, we need to create the content of the survey tool to be included in the Facebook application.

I prefer to use Survey Monkey for my research, but you can use any web service that gives you a link to embed your survey. So, if you’re already familiar with Survey Monkey you can scroll down and skip this step. Go ahead and create an account at Survey Monkey and create a survey. Their design tools are very straight forward, so if should take you no time at all to write a few sample questions. After you’ve finished adding questions click ‘Send Survey’ and it will ask you how you want to collect responses. Specify that you’d like to ‘Add the survey to your website’ and that you want to embed it on your web page. It will ask you for dimensions, which your can enter something around 700px wide by 800px high (you can always go back and adjust them after you’re done. After clicking ‘save’ it will give you a code snippet that you can copy and save for later. Here’s what that looks like:

Liquid error: No API key or secret defined !

So, now you’ve completed the survey tool. All that’s left is to put the data gathering files in place. I’ve built a package that collects a bit of information about the user that is available for download here. Open up the config.php file in your preferred text editor (Textedit for Mac, Notepad for PC, etc.) and put your Facebook App’s ‘id’ and ‘secret’ codes in place of the xxxxx’s. You should also place that Survey Monkey code snippet between the <center> tags. Save and upload those files to the directory on your hosting server that corresponds with your Facebook application.

1
2
3
4
5
6
7
8
9
<!-- Replace the xxx's with your application's id and secret strings... -->
<!--?php <br ?--> define("FACEBOOK_APP_ID", 'xxxxxxxxxxxx');
define("FACEBOOK_SECRET_KEY", 'xxxxxxxxxxxxxxxxx');
?>

<center>
<!-- Paste your survey Code below this line... --></center>

<!-- ...and above this line -->

One last step and then you’re all done. You need to make sure that the ‘index.php’ file has write permissions to the directory where you put them. What does that mean? Basically, every time someone uses your survey on Facebook, that file will create another file with all of the information about the user that you can compare for analysis. How do you change the permissions? It varies from computer to computer. If you are using a FTP client like Cyberduck, you can right click on the index.php file and click write and execute and do the same for the directory in which it is located. If you’re at a loss google ‘change permissions’ along with whatever program you are using to upload files.

So, what does this application do? If you go to my application’s homepage on Facebook ( http://apps.facebook.com/fbrsrchsurvey/), you’ll be prompted with a permissions dialog box asking you the accept. Click ‘allow’ and you should see a sample survey. If you complete the survey, the results will be stored just like any other survey on Survey Monkey on their website. Additionally, the application gathers extended information about the survey taker in the same directory where you uploaded those files. For every user who completes your survey you’ll see a file called ‘FirstName LastName.txt’. If you go to here, you’ll see all the info the application gathered from me. Specifically, it gathers the following items:

Name User ID
Birthday Gender
Religion Political View
Hometown Current Location
A List of Friends Significant Other
People Who Post on Their Wall People on Their Friendlists
People Tagged in Photos With Their College Year
Pages They Have Liked Music They Like
Books They Like Their Profile Interests
Their Profile Activities

You’ll notice that most everything is represented by a number. Facebook uses a number to represent every object, whether that’s a person, place or thing. If you’re curious what the object is, go to a web browser and type graph.facebook.com/ followed by the object number. For example, my user object is http://graph.facebook.com/904260.

You can take these files from your server and correlate them with the data gathered from your Survey Monkey results. As always, make sure to include a common identifier like the user’s name in your survey so you can cross tabulate the results. While there are limitless possibilities of what you can gather from this Facebook package here are a few of my favorites:

  1. Compare shared phototags with active engagement of posts on the user’s wall.
  2. Analyze the volume and distribution of Facebook Likes by Political View, Gender, or Religion.
  3. Analyze the Gender distribution of friendlist usage.

So that’s all that you need to get going to collect information from users on Facebook. If you have any comments or suggestions feel free to let me know. Twitter is coming up next.

Happy data gathering!

App for Gathering Public Data

App for Gathering Data from Survey Users

← Tools for Using Twitter as a Sociological Method This Is What A Scientist Looks Like →

You can find me at the new school, twitter, google, linkedin, facebook, and gmail. I'm happy to help on media and sociology research projects and can answer questions you have about the sociology of social media. Feel free to contact me at the new school or learn more about me at my social links.