Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Facebook SDK v5 for PHP with Phalcon

Hello community,

I have to integrate Facebook login in to my project. Im doing an REST Api on backend and looking for "tips" how to do it correctly .. I have found docs on FB developer page, but would be great if some1 allready did this integration to give some tips...


edited Feb '16

Hi, i had to do this few weeks ago and I used this:

total time to make it work ( without facebook app registration crap ) : 20 mins

here are my functions:

Lets create a static function in our Utils class that will generate the return URL.

public static function getFacebookLoginUrl(){

            $provider = \Phalcon\Di::getDefault()->get('facebook');

            $authUrl = $provider->getAuthorizationUrl([
                'scope' => ['email', 'public_profile']

            \Phalcon\Di::getDefault()->get('session')->set('oauth2state',  $provider->getState());

            return $authUrl;

Lets register the service that will contain our app data: ( in your boostrap.php or so )

        $this->di->setShared('facebook', function() {
            return new \League\OAuth2\Client\Provider\Facebook([
                'clientId'          => 'xxxxxx',
                'clientSecret'      => 'xxxxxx',
                'redirectUri'       => 'http://xxxxxxt/users/facebook/auth',
                'graphApiVersion'   => 'v2.5',

and this is my contoller that recieves the ruturn URL... ( basiccaly after the user enters his creadentials in facebook and agree with terms etc...

        class FacebookController extends Controller {

    public function authAction(){

        if (isset($_GET["error_code"]) && $_GET["error_code"] != ""){
        } else {
            $provider = $this->di->get('facebook');

            $token = $provider->getAccessToken('authorization_code', [
                'code' => $_GET['code']

            $user = $provider->getResourceOwner($token);



and finally lets put the button:

<a href="<?php echo \CommonClasses\Utils\Main::getFacebookLoginUrl(); ?>" class="fa fa-3x fa-facebook-square"></a>

//this calls the first function that i wrote

edited Feb '16

Hey man, thx for helping ... So you made a service with second block of code from abovet? Right ? .. Third one goes in FacebookController..

edited Feb '16

i edited my post. Let me know if you need more info



where can i implement the static function? Don't understand what "our Utils class" is :-)

I am using Vokuro.

Rgds Stefan


$loader->register("myapp\Utils", "app/Utils");

//file app/utils/Utils.php

class Utils .....

simple put the class wherever you want, or add it in controller. Donest really matters

is working ?