Topic-icon Facebook Photos

Support Specialist
12 years 4 months ago #40323 by alzander
Replied by alzander on topic Facebook Photos
Ivan,
When the user logs in, we refresh their access token. Additionally, we always fetch a 'long-lived' access token which lasts for 2 months instead of the standard 2 hours. If the user is logging in using JFBConnect/Facebook, the token should not be invalid.

So, that's something to investigate if you want. You can echo out the user's token that's trying to be used and use the Token Debugger below to check it's validity:
developers.facebook.com/tools/debug/accesstoken/

Finally, if you just want to grab the token out of the database, add this function to the /administrator/components/com_jfbconnect/models/usermap.php file:
function getUserAccessToken($jUserId, $provider)
    {
        $query = $this->_db->getQuery(true);
        $query->select($this->_db->qn('access_token'))
                ->from('#__jfbconnect_user_map')
                ->where($this->_db->qn('provider') . ' = ' . $this->_db->q($provider))
                ->where($this->_db->qn('j_user_id') . ' = ' . $this->_db->q($jUserId));
        $this->_db->setQuery($query);
        $token = $this->_db->loadResult();
        if ($token)
            $token = json_decode($token);
        return $token;
    }
Then, you can just call:
$token = JFBCFactory::usermap()->getUserAccessToken('123', 'facebook');
That function is being added in the next release of JFBConnect, so doing it that way will make your code work going forward.

I hope that helps,
Alex
The topic has been locked.
Support Specialist
12 years 4 months ago #40324 by alzander
Replied by alzander on topic Facebook Photos
Oh.. once you have the token, update your api call like:
$params = array();
$params['access_token'] = $token;
return $this->api('me/albums', $params);
Best of luck!
Alex
The topic has been locked.
Active Subscriptions:

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

I added the code you mentioned above but i got a COM_JFBCONNECT_FB_API_ERROR(#100) The parameter name is required.

So I modified it and tried this instead. But not sure if its correct.
	function getAlbums ($userid)
	{
	   
       $token = JFBCFactory::usermap()->getUserAccessToken($userid, 'facebook');
       
      // echo $token;
		try {
		
		//return $this->api('me/albums');
       $params = array();
       $params['access_token'] = $token;
      
       return $this->api('me/albums', $params['access_token']);
       
		}
         
		catch (Exception $ex) {

			return array();
		}
	}



With the modifications to your original suggestions I get the initial error again where is says COM_JFBCONNECT_FB_API_ERRORAn active access token must be used to query information about the current user. I checked the debugger with the access token when i make the call and I get that it is valid. So I'm not sure why im getting the initial error if i am passing a valid access token after re-logging in. Maybe your code i modified is wrong?

I am still confused as to why im getting this error if i am already logged in as a fb user and just trying to access the user photos with the function i posted above.

With the original code i posted above(without the params) I would get the initial error - but If i would click on the button it would reload the page and i would see the photos.

With the code you posted above this post I would get COM_JFBCONNECT_FB_API_ERROR(#100) The parameter name is required - and the modified version i posted above I would get the initial error again which is COM_JFBCONNECT_FB_API_ERRORAn active access token must be used to query information about the current user. Hope Im not getting you confused but the scenarios is that I am not getting the albums listed when i re-log in. I can just either show the button again and have the users click on it and reload or figure out why i need another active access token.
Last edit: 12 years 4 months ago by Ivan.
The topic has been locked.
Support Specialist
12 years 4 months ago #40354 by alzander
Replied by alzander on topic Facebook Photos
You shouldn't be passing in just the access_token to that function, you should pass in the whole $params array, like:
return $this->api('me/albums', $params);
That will make sure the token from the database is used that you fetched and not whatever may be stored for the current session.

I'm still not sure why the current session token isn't working, but hopefully the above will get you going.

Let me know how that goes, and good luck,
Alex
The topic has been locked.
Active Subscriptions:

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

I tried your original code above as you told me and i got the error: COM_JFBCONNECT_FB_API_ERROR(#100) The parameter name is required.

So thats why i modified it and posted it here.
The topic has been locked.
Support Specialist
12 years 4 months ago #40402 by alzander
Replied by alzander on topic Facebook Photos
Ahh.. I missed that message before. That error message is telling you that the token is valid, but that there is additional missing information. Specifically, the album name is missing. Please see the developer docs for retrieving an album below:
developers.facebook.com/docs/reference/api/album/

To get the album you want, I think you'd need to also have:
$params['name'] = "Album name"
I'm not sure how to retrieve a list of albums, if that's what you're looking for. Hopefully, the above gets you started on what you're looking to do though.

Thanks,
Alex
The topic has been locked.