You can automate creating Facebook apps with Symfony.
If you dont know about symfony’s basics you should read the symfony documentation first.
Here is the instructions:
1) You can use a whole symfony application to develop a facebook app or you can use just a module of a symfony app as your facebook app. I recommend using just a module of your symfony app for small and middle scale Facebook apps.Here i will give instructions for a module.
2) Create your module in your symfony project: symfony init-module your_symfony_app module_name.
For example symfony init-module recent timetravel for me.
3) Add a view.yml under your module’s config directory with this cotent:
all:
has_layout: on
layout: time
stylesheets: [-*]
javascripts: [-*]
Here the layout name is “time” for my application.You should add your layout page under your_symfony_app/templates directory
for me its time.php.Then, you can configure your layout there.My layout page time.php contains just this code:
<div id=”timeAll” style=”margin: 10px;padding: 10px;min-height:450px;height:auto !important;height:450px;color: lime;”>
<?=$content?>
</div>
4) Add Facebook PHP5 api classes under your_module/lib directory.They are 2 files:
facebook.php and facebookapi_php5_restlib.php
Make sure that there is no include or require statements in that files.since symfony autoloads these classes when you put them under lib directory, no need for include and require statements so remove if there exists.
Then clear symfony cache using symfony cc
5) Open your_module/actions.class.php and edit the index action ( executeIndex() function )
If there is a default forward line just remove it. Then paste this code to manage facebook authentication,
<?php
// catch the exception that gets thrown if the cookie has
// an invalid session_key in it
try
{
if (!$this->facebook->api_client->users_isAppAdded())
{
$this->facebook->redirect($this->facebook->get_add_url());
}
# your code here
}
catch (Exception $ex)
{
// this will clear cookies for your application and
// redirect them to a login prompt
$this->facebook->set_user(null, null);
$this->facebook->redirect($this->appcallbackurl);
}
open your_module/templates/indexSuccess.php and write “Hello Facebook” then save it.
6) Add a preExecute function to your module’s actions.class.php like this:
public function preExecute()
{
$this->appcallbackurl = ‘http://www.your_domain.com/your_module_name’;
$this->appcanvasurl = ‘http://apps.facebook.com/your_facebook_app_name’;
$appapikey = ‘your_facebok_api_key’;
$appsecret = ‘your_facebook_secret_key’;
$this->facebook = new Facebook($appapikey, $appsecret);
$this->user = $this->facebook->require_login();// id of Facebook user hat will add your app.Then, you can use $this->user in your all actions to get user id.
}
7) Create your new facebook app and give your index action’s url as your callback url.
for example this is enough if you use your index action of the module as hompage of your facebook app:
http://www.mydomain.com/my_symfony_module
Type your canvas url on your browser and add your app to your facebook account.
Shouldn’t you put the exception code in the preExecute as well? Just in case someone tries starting the application through another action?
I’m also wondering what kind of application(s) you’ve made with symfony. It looks like it’s been a few months since you’ve posted.
I gave the skeleton just.You can (should) add some other code & controls to the code of course, you are right.
I have created many applications personally.
http://www.facebook.com/developers/apps.php?app_id=21511541408
http://www.facebook.com/developers/apps.php?app_id=5761882846
http://www.facebook.com/developers/apps.php?app_id=6300269482
are some of them.