Aug 232010
 

The Graph API gives you access to public information. If you need more you have to have an access token. There are a couple of ways of gaining one, but first you need to create an application and get an App ID & App Secret.

  1. Create application here: http://www.facebook.com/developers/
  2. Click Setup Application in the upper right and follow the steps
  3. Create a link to the auth page:
    1. https://graph.facebook.com/oauth/authorize?client_id=APP-ID-HERE&redirect_uri=http://URL-TO-REDIRECT-TO&scope=read_stream&type=user_agent
    2. client_id should be set to your application ID. You can find it on this page.
    3. redirect_uri is the URL you want Facebook to redirect to with the access token in the URL in this format: http://example.com/facebook-app.php#access_token=452452ACCESS-TOKEN-HERE
  4. When the user clicks the link they will be brought to a Facebook Allow/Deny app page. If you need additional permissions such as access to feeds you’ll have to configure scope (&scope=read_stream,read_friendlist). Read here for more information.
  5. After the user allows the app they will be forwarded to the redirect_uri and the access token will be in the URL in the format mentioned above.

This code can be used to pull the access token out of the URL:

?View Code JAVASCRIPT
var url = location.href;
var access_token = url.split('=')[1].split('&')[0];
/* Assumes default format without any parameters/variables added to the url by the user */

The access token can be accessed via the “access_token” variable

Share
Aug 232010
 

This is the first post in a mini series about the Facebook Graph API.

About It
The Graph API offers information about users, groups, pages, applications, photos, videos, events and more. You submit a query to the API and it returns information in JSON format.

Why it’s important
The Graph API makes it really easy to pull data from Facebook and add it to your applications. You can make custom applications that sort feeds, photos, organize them and post new data. No need to make complicated applications or get angered every time Facebook changes the look.

How it works
Your web app sends an AJAX request to http://graph.facebook.com/ID# where the ID# can be of anything mentioned above. Example: http://graph.facebook.com/4 will show you some information on Mark Zuckerberg, the person who is ID4.

More information:
http://developers.facebook.com/docs/api

Share
Aug 202010
 

There are plenty of free services out there that will check if your websites are up (list) and these are great for someone for just wants occasional checks. Most of these services are quite limiting and require you to sign up and create an account when all you want is a simple test.

Recently my internet service has been down multiple times a week and I wanted to setup monitoring. I checked out Pingdom and Mon.itor.us, but there free services didn't check frequently enough. I did some searching and came across a script I could run off my web server (with decent uptime). The script didn't quite meet my needs so I adapted it into the following:

#!/bin/bash
 
HOSTS='example1.com example2.com'
savePath=/home/username
 
for thisHost in $HOSTS
do
  pingResults=`ping -c 4 $thisHost | grep 'received'`
  received=`echo $pingResults | awk -F',' '{print $2}'`
  packetLoss=`echo $pingResults | awk -F',' '{print $3}'`
 
  time=`date | awk '{print $4}'`
  day=`date | awk '{print $3}'`
  month=`date | awk '{print $2}'`
  year=`date | awk '{print $6}'`
 
  date="$year, $month, $day, $time"
 
  echo $date, $packetLoss >> $savePath/ping_$thisHost.csv
done

You'll need to add the websites you want to check and change the location of the log file. The script generates a log named "ping_example.com.csv" that contains the time and date of ping and the packet loss.

To automate to the process you can add a cronjob that executes the script every few minutes. Upload the ping script to your server. After it's uploaded, SSH into your server and type the following:

crontab -e

This will open your crontab file containing all your cronjobs. Add the this line to the bottom:

*/3 * * * * sh -c $'/path/to/ping/script/ping.sh'

"*/3" runs the script every 3 minutes. You can change 3 to any value 0-59.

 

To save and exit the editor:

For emacs
emacs editor
Ctrl-x then Ctrl-c then hit 'y'

For joe
Joe editor
Ctrl-K then x

For nano
Nano editor
Ctrl-x then 'y' then [enter]

After editing and saving the file cron should automatically run the uptime checker script every 3 minutes and save the results to "ping_example.com.csv". You can open this in Excel or another spreadsheet program and generate graphics or reorder/organize it to make it easier to read.

Here are some free alternatives:
Pingdom
Mon.itor.us
Are my sites up?

Share