Topic-icon Facebook Photos

Active Subscriptions:

None
12 years 5 months ago - 12 years 5 months ago #39990 by Ivan
Facebook Photos was created by Ivan
Hi,


In my component i added the facebook libray like so:

$fbClient = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $fbClient->getFbUserId();

I then check if the user has the user_photos permissions like so:
$cookie = $_COOKIE['jfbconnect_permissions_granted'];
$cookie = json_decode($cookie);
if (!in_array("user_photos", $cookie)) {

Show Button Code here

}

I made modifications to components/com_jfbconnect/libraies/provider/facebook.php
	function getAlbums ()
	{
	       
		try {
		
			return $this->api('me/albums');
            
            
		}
         
		catch (Exception $ex) {
  
			return array();
		}
	}
   

When a user initially logs in and connects and asks for photos permission i make the request for the photos using:
  $albums = $fbClient->getAlbums();

  

Now If I am to log out and then log back in making the call above causes this error:

COM_JFBCONNECT_FB_API_ERRORAn active access token must be used to query information about the current user.

I would have to click on a button like this:
   <div class="sourcecoast" style="margin-top:6px;text-align:center;">
<a class="btn btn-large btn-primary" href="javascript:void(0)" onclick="jfbc.login.facebook(); ">Import Facebook Albums</a>
</div>

And then refresh the page so i could see the the albums. Do you know why this might be happening?
Last edit: 12 years 5 months ago by Ivan.
The topic has been locked.
Support Specialist
12 years 5 months ago #40000 by alzander
Replied by alzander on topic Facebook Photos
How are you logging back in? Is the user logging in using Facebook, or just using their Joomla credentials? If they aren't logging in with Facebook, then the token for that user wouldn't be stored in the session. You'd need to pull the token out of the database for that user and pass it along with the API call. We're looking into automatically getting the user's token for API calls in the future, regardless of how they logged in, if a token exists.. but right now, it's a manual process.

Let me know if that sounds right, and if so, we can help you implement it.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 5 months ago #40001 by Ivan
Replied by Ivan on topic Facebook Photos
Yes I am logging in via Facebook. How can I make this work.
The topic has been locked.
Active Subscriptions:

None
12 years 5 months ago #40109 by Ivan
Replied by Ivan on topic Facebook Photos
Alex, can you help out with this
The topic has been locked.
Active Subscriptions:

None
12 years 5 months ago #40142 by Ivan
Replied by Ivan on topic Facebook Photos
Hi,

I upgraded to the latest version of JFBConnect for Joomla 2.5

I added the code below :
<div class="sourcecoast" style="margin-top:6px;text-align:center;">
<a class="btn btn-large btn-primary" href="javascript:void(0)" onclick="jfbc.permissions.update_scope('user_photos'); jfbc.login.provider('facebook');">Import Facebook Albums</a>
</div>

The code does ask for photo permissions but does not reload the page. After the dialogue box closes I would like to reload the page. Can you help me achieve this.
The topic has been locked.
Active Subscriptions:

None
12 years 5 months ago #40191 by Ivan
Replied by Ivan on topic Facebook Photos
Alex,

Have you had a chance to look at this.
The topic has been locked.
Support Specialist
12 years 5 months ago #40197 by alzander
Replied by alzander on topic Facebook Photos
Ivan,
I just looked at our code to come up with the best solution. I think the following should work, but you'll have to test. Please edit the /components/com_jfbconnect/includes/jfbconnect.js file. Around line 46, you'll see:
if (!jfbc.login.logged_in)
                    jfbc.login.facebook_onlogin();
                else
                    jfbc.permissions.fetch();
Update that to:
if (!jfbc.login.logged_in)
                    jfbc.login.facebook_onlogin();
                else
                {
                    jfbcJQuery(document).one("jfbc-permissions-fetched", function () {
                        location.reload(true);
                        });
                    jfbc.permissions.fetch();
                }
The jfbc-permissions-fetched event is called after the new permissions are grabbed and set into the cookie. Then, the location.reload should reload the page. That will let your PHP code be able to see the updated cookie and do what it needs to do.

Please test and let me know how that goes. I didn't test directly, but the code looks good from what I can tell.

Thanks, and good luck,
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 4 months ago #40236 by Ivan
Replied by Ivan on topic Facebook Photos

alzander wrote: Ivan,
I just looked at our code to come up with the best solution. I think the following should work, but you'll have to test. Please edit the /components/com_jfbconnect/includes/jfbconnect.js file. Around line 46, you'll see:

if (!jfbc.login.logged_in)
                    jfbc.login.facebook_onlogin();
                else
                    jfbc.permissions.fetch();
Update that to:
if (!jfbc.login.logged_in)
                    jfbc.login.facebook_onlogin();
                else
                {
                    jfbcJQuery(document).one("jfbc-permissions-fetched", function () {
                        location.reload(true);
                        });
                    jfbc.permissions.fetch();
                }
The jfbc-permissions-fetched event is called after the new permissions are grabbed and set into the cookie. Then, the location.reload should reload the page. That will let your PHP code be able to see the updated cookie and do what it needs to do.

Please test and let me know how that goes. I didn't test directly, but the code looks good from what I can tell.

Thanks, and good luck,
Alex


Okay Alex this seems to do the trick!! The only thing is that If the user were to log out and come back to this page that has this button I would get a error :
COM_JFBCONNECT_FB_API_ERRORAn active access token must be used to query information about the current user.

This is because the user has logged out an needs an active access token. Could this be easily achieved?

How would you achieve this?
The topic has been locked.
Support Specialist
12 years 4 months ago #40293 by alzander
Replied by alzander on topic Facebook Photos
Ivan,
I'm a little confused. If you have the button like you show above:
<a class="btn btn-large btn-primary" href="javascript:void(0)" onclick="jfbc.permissions.update_scope('user_photos'); jfbc.login.provider('facebook');">Import Facebook Albums</a>
That should always try to login the user in (if they aren't already) and update their permissions (if they aren't correct). Is the login window not popping up and asking the user for their credentials again when they try to login?

The other option, if you already have the user's Joomla ID and know they've authenticated with Facebook before, is to look up their access_token in the xyz_jfbconnect_user_map table. That should have the permissions they previously granted. With the next release (in February), we'll have an easy call to get that token as we'll be using it for more features like this. Until then, you'd need to make the query for the database to get it (we can help if you need).

I hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 4 months ago - 12 years 4 months ago #40311 by Ivan
Replied by Ivan on topic Facebook Photos
Alex,

What is happening is that I am experiencing the scenario where the user has logged out and then re-logged in using JFBConnect. So there is no access token as stated here:

How to Handle Expired Access Tokens

In components/com__jfbconnect/libraries/provider/facebook.php

I added:
	function getAlbums ()
	{
	       
		try {
		
			return $this->api('me/albums');
       
		}
         
		catch (Exception $ex) {

			return array();
		}
	}

Because Im using the php cookie script to detect if the user already has permissions then the function above gets called since I already have permissions.

It seems i need to query the DB like you said to get the access token. How would you achieve this?
Last edit: 12 years 4 months ago by Ivan.
The topic has been locked.