Welcome Guest, Not a member yet? Register   Sign In
Getting CodeIngoter to play nicely with facebook
#11

[eluser]coldclimate[/eluser]
-- A multi-site tangent --

We have also implemented a very rough form of multi-site config, just to make our lives easier. Because Facebook relies on callback URLs, developing locally on your machine is tricky, and we've ended up with an app per developer. The problem being that each app needs it's own config, and with a junior team only just getting to grips with version management, people kept standing on each others toes and checking their personal config in over the live app. The fix - more education, but also a "contact aware app", which switches config settings depending on what domain it finds itself sitting on. This is all pretty rough at the moment, but is up and running.

It works by detecting the host that the application is running on ($_SERVER['HTTP_HOST']) and setting a site wide constant based on it. This constant is then used in config.php, database.php and facebook.php to switch between config arrays. We also define a boolean constact for "quick switching" so we can turn logging on in dev, tracking on in live etc etc.

We made changes to the following files:

/index.php (the root index file)
Added the following lines near the top (domains changed to protect the innocent)

Code:
switch ($_SERVER['HTTP_HOST']) {
    case "live.wishli.st":
        define('site_identifier', 'live', TRUE);
        break;
    case "test.wishli.st":
        define('site_identifier','test', TRUE);
        break;
    case "dev1.wishli.st":
        define('site_identifier','dev1', TRUE);
        break;
    
    case "dev2.wishli.st":
        define('site_identifier','dev2', TRUE);
        break;
}

if (site_identifier == 'live')
{
    //we are in live!
    define('SITE_LIVE', TRUE);
}
else
{
    //somewhere else - could be dev or indeviduals test
    define('SITE_LIVE', FALSE);
}

We can now use 'site_identifier' in case switches as follows:

/application/config/config.php
-to switch the base_url and the the logging levels (base_url example shown only)
Code:
//default to test, so if something goes wrong we don't screw live
$config['base_url']    = "http://apps.facebook.com/our-app-name1/";

switch (site_identifier) {
    case "live":
       $config['base_url']    = "http://apps.facebook.com/our-app-name2/";
        break;
    case "test":
        $config['base_url']    = "http://apps.facebook.com/our-app-name1/";
        break;
    case "dev1":
       $config['base_url']    = "http://apps.facebook.com/our-app-name3/";
        break;
    
    case "dev2":
       $config['base_url']    = "http://apps.facebook.com/our-app-name4/";
        break;
}

/application/config/database.php
-to switch between database config sets
Code:
//default to test
$active_group = "test";

// now choice correct one
switch (site_identifier) {
    case "live":
       $active_group = "live";
        break;
    case "test":
       $active_group = "dev";
        break;
    case "dev1":
       $active_group = "dev1";
        break;
    case "dev2":
       $active_group = "dev2";
        break;
}

And then define an active group for each environment
$db['dev1']['hostname'] = "xxx";
$db['dev1']['username'] = "yyyy";
$db['dev1']['password'] = "zzzz";
$db['dev1']['database'] = "aaaaaa";
...etc etc
$db['dev2']['hostname'] = "bbb";
$db['dev2']['username'] = "ccc";
$db['dev2']['password'] = "ddd";
$db['dev2']['database'] = "eee";
/application/config/facebook.php
- the same trick as above - change the config array based on the switch.
Code:
/default is test
$config['facebook_api_key'] = 'aaaaa';
$config['facebook_secret_key'] = 'bbbbb';

// now switch based on site_identified
switch (site_identifier) {
    case "live":
        $config['facebook_api_key'] = 'ccccc';
        $config['facebook_secret_key'] = 'dddd';
        break;



Eventually I'll clean this up and make it into a CI mod of some kind, for the moment, it's how we roll.
#12

[eluser]Kumar Chetan sharma[/eluser]
Code:
while(1){
  echo 'thanks a ton!!!';
}
#13

[eluser]garycocs[/eluser]
[quote author="oli:wishli.st" date="1273609450"]

$_GET:
FB throws you lots of stuff in the URL, and whilst we'd love to make use of it (track referrers etc) we had to stop it to make CI play nicely. FB will stuck things like ?id=2579980995&ref=ts on the end of your URLS, and then CI will 404.

To ditch all the information being passed by get we added a hook. Basically every request to the app now gets it's $_GET ditched. Eventually we'll handle this more gracefully. In /application/hooks we created Querystring.php with the following content
Code:
<?php
class Querystring  {
    public function rewrite () {
        $_GET = array();
    }
}
?>

[/quote]

Could you expand this further? I have set up the application http://apps.facebook.com/myguideireland/ and it does work but the problem is with the redirect after authentication? It tries to go to this url http://apps.facebook.com/myguideireland/?session={"session_key":"2.wl_q5rCDFXLf_8COjFSCvA__.3600.1274720400-750791302","uid":750791302,"expires":1274720400,"secret":"Ou1I772u0hb4R7Br_8C7gQ__","sig":"da04229a010e38c24f3cb8958b9fc964"} which obviously returns an error.

I added Querystring.php into the hooks folder and enabled Hooks in config.php but I am still receiving this error? I have also modified the .htaccess to remove the index.php from the url but I don't think this has anything to do with the problem at hand.

Thanks for any help you can give me.

//Gary
#14

[eluser]Kumar Chetan sharma[/eluser]
Go to syste/application/config/config.php and change the following
Code:
$config['uri_protocol']    = "AUTO";
to
Code:
$config['uri_protocol']    = "PATH_INFO";
Do let me know if it works for you.
#15

[eluser]garycocs[/eluser]
That worked all right now SAVAGE, thanks for your help Kumar.

You don't know any good resources to get going building something interactive??
#16

[eluser]coldclimate[/eluser]
What sort of interactive are you looking for @garycocs
#17

[eluser]garycocs[/eluser]
Well I managed to find out how to invite friends and post things to peoples walls so that's a step forward, I guess I'm wondering what can this do now I have it up? What applications are people building etc?

Can you integrate the open graph like buttons into the application??

//Gary
#18

[eluser]coldclimate[/eluser]
No ikea what everybody else is building yet, but look up your local Facebook Developer garage and I'll place a bet that a good amont are PHP backed.

We're just in the process of converting to the new API and some of the goodies that the graph delivers.
#19

[eluser]garycocs[/eluser]
Hmmm being in Cork, Ireland I'm not sure how 'local' my local Facebook Developer garage really is Smile

So the new API will need a new php conversion for CodeIgniter? I'd be interested in seeing what goodies are coming out with the new API, if you need any help just let me know.
#20

[eluser]Kumar Chetan sharma[/eluser]
This is for oli:wishli.st, I am loading facebook PHP SDK after making some changes in the constructor. Instead of passing args, I am passing it an array as you may do in CI. Though I will never ever edit a 3rd party library but I did for FB.
For garycocos, imagination rules the world. I am bound by time other wise my my mind is always full of ideas. Some times I feel Facebook used my idea that I had in 2002 ;-), I wanted to enhance a discussion forum and allow users to host a page, some thing like devshed and deviantart with chatting.

Look around you and you will certainly come up with an idea.




Theme © iAndrew 2016 - Forum software by © MyBB