Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook PHP SDK Connection
    primarykey
    data
    text
    <p>I've been searching this site for the answer for a while and I haven't been able to find one for this problem so I'm hoping someone can give me a hand. I'm not exactly an experience PHP programmer so there could be something severely wrong with what I'm doing.</p> <p>Anyways I am working with another developer who doesn't code in PHP at all and needs access to Facebook information. That being said I'm trying to develop a facebook class which encapsulates all of the Facebook graph calls, allowing for my buddy to call a single function and get all of the information he needs without having to worry about any of the Facebook PHP SDK functions at all. This class I've put in a separate file called CFacebook.php. The code for this class can be found below (I've simply copied the example off of the facebook website)</p> <pre><code>&lt;?php require_once 'facebook.php'; class CFacebook { //private variables private $Config = ""; private $FBObject = ""; private $Code = ""; private $Session = ""; private $AppId = '*************'; private $ApiSecret = '*******************'; //I have the API secret and AppID in //here but for privacy reasons I've taken them out //constructor public function CFacebook() { $this-&gt;FBObject = new Facebook(); $this-&gt;FBObject-&gt;setApiSecret($this-&gt;ApiSecret); $this-&gt;FBObject-&gt;setAppId($this-&gt;AppId); } //Get profile information public function GetFBProfileInformation() { $FBProfile = ""; $ID = $this-&gt;FBObject-&gt;getUser(); echo "&lt;br /&gt;"; if($ID) { try { $FBProfile = $this-&gt;FBObject-&gt;api('/me','GET'); return $FBProfile; }catch (FacebookApiException $e) { //send back to UI to have user sign in // If the user is logged out, you can have a // user ID even though the access token is invalid. // In this case, we'll get an exception, so we'll // just ask the user to login again here. echo "has ID &lt;br /&gt;"; $login_url = $this-&gt;FBObject-&gt;getLoginUrl(); echo 'Please &lt;a href="' . $login_url . '"&gt;login.&lt;/a&gt;'; echo $this-&gt;FBObject-&gt;getAccessToken()."&lt;br /&gt;"; echo $this-&gt;FBObject-&gt;getApiSecret()."&lt;br /&gt;"; error_log($e-&gt;getType()); error_log($e-&gt;getMessage()); } }else { //return to UI taht user isn't logged in and have user re-sign in //If the user is logged out, you can have a // user ID even though the access token is invalid. // In this case, we'll get an exception, so we'll // just ask the user to login again here. $Page = "http://fratlabs.com/FacebookTest.php"; $login_url = $this-&gt;FBObject-&gt;getLoginUrl(array('scope'=&gt;'email,publish_stream,user_likes,user_hometown','redirect_uri'=&gt;$Page)); //$logout_url = $this-&gt;FBObject-&gt;getLogoutUrl(array('next'=&gt;'http://fratlabs.com/FacebookTest.php')); echo 'Please &lt;a href="' . $login_url . '"&gt;login.&lt;/a&gt;'; //echo 'Logout Url: &lt;a href="'. $logout_url.'"&gt;Logout&lt;/a&gt;'; error_log($e-&gt;getType()); error_log($e-&gt;getMessage()); } //echo $this-&gt;FBObject-&gt;getLogoutUrl(array('next'=&gt;'http://fratlabs.com/FacebookTest.php')); } </code></pre> <p>};</p> <p>?></p> <p>This class is included and instantiated in a test page which is where the Facebook login is returned too. Maybe I need to include all of these calls in the same page as the one the facebook login is returned to? The only thing that is confusing me is that once every blue moon the code will work and I will actually create a link to Facebook, but every other time I'm left staring at the login page with the "please login" link on it.</p> <p>Thank you for your help, I really appreciate it!</p> <p>-Brett</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload