Benultra
Posts: 17
|
Posted: 06/04/2012, 2:46 AM |
|
Hi,
Having a crack at PHP and have trouble using the Facebook API 3.0 with Codecharge Code. If I run the script in a standard PHP page not problems, however use the code inside a function and it doesn't work as planed. Here is my Event page Code.
Basically the $me doesn't return anything. I assume this could be a Variable scoping issue, has anyone else had this problem, our could suggest where I am going wrong?
<?php
include_once("includes/php/facebook/facebook.php");
//BindEvents Method @1-D40060DD
function BindEvents()
{
global $CCSEvents;
$CCSEvents["BeforeShow"] = "Page_BeforeShow";
}
//End BindEvents Method
//Page_BeforeShow @1-27BCD354
function Page_BeforeShow(& $sender)
{
$Page_BeforeShow = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $default; //Compatibility
//End Page_BeforeShow
//Custom Code @2-2A29BDB7
// -------------------------
global $facebook,$Secret,$AppID,$uid,$logoutUrl ;
global $session ;
global $me ;
global $Facebook_Login, $Fackbook_Logout;
$Fackbook_Logout->Visible = false;
$Facebook_Login->Visible = false;
$facebook = new Facebook(array('appId' => "zzzzzzzzzzzzzz" ,'secret' => "zzzzzzz" ,'cookie' => true,));
$session = $facebook->getSession();
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
$user_profile = $facebook->api('/me');
$user_pages = $facebook->api('/me/accounts');
$uid = $facebook->getUser();
$logoutUrl = $facebook->getLogoutUrl();
$Facebook_Logout->Visible = true;
} else {
$loginUrl = $facebook->getLoginUrl();
$Facebook_Logout->Visible = true;
echo "<br> Name = " . $me['first_name']." ".$me['last_name'];
print_r ($me);
}
// -------------------------
//End Custom Code
//Close Page_BeforeShow @1-4BC230CD
return $Page_BeforeShow;
}
//End Close Page_BeforeShow
?>
|
|
|
clahti2
Posts: 107
|
Posted: 06/04/2012, 12:20 PM |
|
did you try
global $me;
at the top of your code? If this doesn't help I will actually read the code
EDIT: Looking at the code I see you did, let me have a deeper look.
Ok, the only thing that comes to mind is maybe this is session related? I have not used the FB API before so I don't know the expected behavior.
|
|
|
Benultra
Posts: 17
|
Posted: 06/05/2012, 12:04 AM |
|
I got this working in a non codecharge page in the same enviroment. So unless Codecharge changes sessions, I cant see that being the issue.
|
|
|
|