This is just a note for me how I test my code to retrieve Facebook Access Token though my Zend Application since Zend_OAuth is not really useful here:
class IndexController extends Zend_Controller_Action
{
const APP_ID = YOUR_APP_ID;
const APP_SECRET = YOUR APP SECRET;
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// redirect user to authorized url. Usually you may want to make a pop up link to open this...
$this->_helper->redirector->gotoUrl(
'https://graph.facebook.com/oauth/authorize?client_id='.
self::APP_ID.
'&redirect_uri=YOUR_CALLBACK_URL');
}
public function oauthAction() {
// if succuess will get 'code' parameters
$code = $this->getRequest()->getParam('code');
if (null !== $code)
{
// This will return an access_token and expiry if success
// $content will be 'access_token=.....&expiry=.....'
$content = file_get_contents(
'https://graph.facebook.com/oauth/access_token?client_id='.
self::APP_ID.
'&redirect_uri=YOUR_CALLBACK_URL'.
'&client_secret='.self::APP_SECRET.
'&code='.$code);
//you may want to parse $content so you can retrieve access_token alone
// Simple Test to retrieve user information
$this->view->user = json_decode(
file_get_contents(
'https://graph.facebook.com/me?'.
$content));
}
else {
// Error Code to handle.. probably user not authorize
}
}
}
My view script file:
User Name: <?= $this->user->name; ?>
Just an idea. maybe should write a service to do all the procedures like Zend_Service_Twitter.