Facebook recently updated their Graph API to require an oAuth access token. Here is a quick guide that explains the easiest way to create an access token for your site.
Create a Facebook App
First you need to create a facebook app that you own / control. To do this go to this url: https://www.facebook.com/developers/ and click "Set Up New App". Enter a name for the app and agree to the terms. It doesn't matter what you name the app. Once that is done go to the Web Site tab on the left and enter the URL for your site in the Site URL box. This is required or you will get an invalid referral error when you try to generate your token.
Once you have your app created copy and paste the "Application ID" we will need this later.
Generating the token
Now we need to build the URL to create our access token. There are 3 important parts to this process.
client_id – This is your Application Id you copied earlier
redirect_uri – this should be the URL to your site
scope – this is what you want the access code to allow access to. If you don't specify "offline_access" the access code will expire when you log out of facebook.
https://graph.facebook.com/oauth/authorize?type=user_agent&client_id=####&redirect_uri=http%3A%2F%2Fitslennysfault.com&scope=read_stream,offline_access
Now you just have to replace the "####" with your application id and "itslennysfault.com" with your website's url and paste it in to your browser's URL bar. You will then be taken to the typical facebook allow permissions page. Once you click "Allow" you will be redirected to your web site with some extra data.
The URL when you are redirected back should look like this:
http://itslennysfault.com/#access_token=######&expires_in=0
Where the ##### is is your access token… copy and paste that and you're good to go. You can use this access code to Get latest status from facebook fan pages in PHP.
Garrett
June 9, 2011 at 4:43 pm
Thank you Thank you Thank you,
This has relieved quite an aggressive headache.
Was very frustrated with Facebook’s OAuth switch.
Euan
June 18, 2011 at 12:15 am
What a great help, thanks for posting this. It’s a pain when fb keeps changing stuff but good peeps like yourself save the day and it’s much appreciated. Cheers!
Romil Dhakar
February 10, 2012 at 2:51 pm
Thanks for the help. Much appreciated. Wish FB could publish your post on their official forum.
Adam Cleaner
March 30, 2012 at 7:27 pm
worked nice and easy without any fuss. thanks
Max Payne
April 4, 2012 at 6:42 am
Hi thanks for your Beautiful tutorial.