First,
Here is the Final Shape of your App Evry1falls
Now,
1) main.php - Code
- As you can see the main.php file holds the Variables from where other files will work through such as (Index.php) .... any question just post a comment !Here is the Final Shape of your App Evry1falls
Final Look Of The Application Using (PHP) |
1) main.php - Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//facebook application | |
$fbconfig['appid' ] = "118487369116"; | |
$fbconfig['secret'] = "e7baab9cae0bd29f2b39ba242d1029f8"; | |
$fbconfig['baseurl'] = "http://evry1falls.freevar.com/test12/"; | |
if (isset($_GET['request_ids'])){ | |
//user comes from invitation | |
//track them if you need | |
} | |
$user = null; //facebook user uid | |
try{ | |
require "facebook.php"; | |
} | |
catch(Exception $o){ | |
error_log($o); | |
} | |
// Create our Application instance. | |
$facebook = new Facebook(array( | |
'appId' => $fbconfig['appid'], | |
'secret' => $fbconfig['secret'], | |
'cookie' => true, | |
)); | |
//Facebook Authentication part | |
$user = $facebook->getUser(); | |
//$user_profile = $facebook->api('/me','GET'); | |
// We may or may not have this data based | |
// on whether the user is logged in. | |
// If we have a $user id here, it means we know | |
// the user is logged into | |
// Facebook, but we don’t know if the access token is valid. An access | |
// token is invalid if the user logged out of Facebook. | |
$loginUrl = $facebook->getLoginUrl( | |
array( | |
'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown', | |
'redirect_uri' => $fbconfig['baseurl'] | |
) | |
); | |
$params = array( 'next' => 'http://evry1falls.freevar.com/index.php' ); | |
$logoutUrl = $facebook->getLogoutUrl($params); | |
if ($user) { | |
try { | |
// Proceed knowing you have a logged in user who's authenticated. | |
$user_profile = $facebook->api('/me'); | |
} catch (FacebookApiException $e) { | |
//you should use error_log($e); instead of printing the info on browser | |
d($e); // d is a debug function defined at the end of this file | |
$user = null; | |
} | |
} | |
//if user is logged in and session is valid. | |
if ($user){ | |
//get user basic description | |
$userInfo = $facebook->api("/$user"); | |
//update user's status using graph api | |
//http://developers.facebook.com/docs/reference/dialogs/feed/ | |
if (isset($_GET['publish'])){ | |
try { | |
$publishStream = $facebook->api("/$user/feed", 'post', array( | |
'message' => "Thanx For Using Evry1falls. :)", | |
'link' => 'http://evry1falls.freevar.com/test12/', | |
'picture' => 'http://1.bp.blogspot.com/_RWM4SJr3-U0/Sqxsjyn3xgI/AAAAAAAAAcQ/3kIdP5QBcfY/S45/evry1falls_t.jpg', | |
'name' => 'PHP Apps', | |
'description'=> 'Checkout PHP apps Toturials from evry1falls.blogspot.com. I found some of them are just awesome!' | |
) | |
); | |
//as $_GET['publish'] is set so remove it by redirecting user to the base url | |
} catch (FacebookApiException $e) { | |
d($e); | |
} | |
$redirectUrl = $fbconfig['baseurl'] . '/index.php?success=1'; | |
header("Location: $redirectUrl"); | |
} | |
//update user's status using graph api | |
//http://developers.facebook.com/docs/reference/dialogs/feed/ | |
if (isset($_POST['tt'])){ | |
try { | |
$statusUpdate = $facebook->api("/$user/feed", 'post', array('message'=> $_POST['tt'])); | |
} catch (FacebookApiException $e) { | |
d($e); | |
} | |
} | |
} | |
function d($d){ | |
echo '<pre>'; | |
print_r($d); | |
echo '</pre>'; | |
} | |
?> |
Next - Index.php