you tried just using local variables and returning the profile? This
is how I have done it in the past and it's worked flawlessly.
On Sep 1, 1:01 pm, koreill1 <korei...@gmail.com> wrote:
> I'm trying to implement Facebook authentication in my app, but I
> cannot get the user. Everytime this code is run, if($this->_userid ==
> 0) is true, which sends the application back to the redirect, which is
> the index page of my application.
>
> I'm using PHP SDK 3.0.1. Can anyone tell why $this->_userid never
> populates?
>
> Thanks
>
> -------------logic----------------
>
> function __construct($apikey = null, $secretkey = null) {
>
> // include the vendor
> App::import('vendor', '/facebook');
> $this->_apikey = $apikey;
> $this->_secretkey = $secretkey;
> // instantiate it
> $this->_instance = new Facebook(array('appId' => $this->_apikey, 'secret' => $this->_secretkey, 'cookie'=> true));
>
> $this->_instance->setFileUploadSupport(true);
>
> $this->_userid = $this->_instance->getUser();
>
> // If the user is not connected to the application, redirect
> the user to authentication page
> if($this->_userid == 0) {
> // If the user is not connected to the application, redirect
> the user to authentication page
> $login_url = $this->_instance->getLoginUrl($params =
> array('redirect_uri' => REDIRECT_URI,'scope' =>
> PERMISSIONS_REQUIRED));
>
> echo ("<script> top.location.href='".$login_url."'</
> script>");
>
> } else {
> // if the user is already connected, then fetch access_token and
> user's information or show some content to logged in user.
> try
> {
> $access_token = $this->_instance->getAccessToken(); //
> Gives you current user's access_token
>
> $this->_userid = $this->_instance->api('/me'); // Gets
> User's information based on permissions the user has granted to your
> application.
>
> } catch(FacebookApiException $e){
> $results = $e->getResult();
> // Print results if you want to debug.
> }
>
> }
>
> }
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment