Topic-icon Jfbconnect not detecting Community Builder

Active Subscriptions:

None
13 years 11 months ago #24068 by rajsin
Hi,

I tried the access token to update the user facebook information into my database. But it is invalid as soon as the user logged out from my website (User was loggied in using connect Login Using Fcaebook). In your previous post you mentioned that it stays valid for 24 hours.

Thanks
Rajneesh
The topic has been locked.
Active Subscriptions:

None
13 years 11 months ago #24069 by rajkum
Hi,

I tried the access token to update the user facebook information into my database. But it is invalid as soon as the user logged out from my website (User was loggied in using connect Login Using Fcaebook). In your previous post you mentioned that it stays valid for 24 hours.

Thanks
Rajneesh
The topic has been locked.
Support Specialist
13 years 11 months ago #24074 by alzander
Rajneesh,
How are you trying to update the user's information? JFBConnect doesn't currently support fetching a users information when they are offline/logged out of your site. It's something we're looking into adding. For now, if you're doing that, you'd have to be adding a bit of custom code to call the Facebook API with a specific user's access token. JFBConnect does make that process a lot easier (we wrap the API and store the token already), but it would still take some work to do what you're looking for.

Can you post the code you're using so we can check what might be going wrong, or can you explain further what you're trying to do?

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

None
13 years 11 months ago #24086 by rajkum
graph.facebook.com/Facebook_ID?access_token=

I am using this facebook API. In the URL above Facebook_ID is replaced by User Facebook Id and access_token is replaced by access token which we obtained once the user log in to our website using Login With Facebook Button(JfbConnect table jfb_connect_user_map table provides both Facebook_ID and access_token).

One more issue i need to ask:
If the user does not allow the facebook application to access the information it is asking for, how we can capture this event in JFBConnect.
Thanks
Rajneesh
The topic has been locked.
Active Subscriptions:

None
13 years 11 months ago #24135 by rajkum
Hi,

When the user allows the facebook application to access his/her requested information from his/her facebook account, i want to call a particular function of my application. Where i can add this function call into jfbconnect source code.

Thanks
Rajneesh
The topic has been locked.
Support Specialist
13 years 11 months ago #24139 by alzander
Rajneesh,
If you're using JFBConnect's api function, it will return the response from Facebook itself. You can parse that out, which will have errors like "Permission not granted", I believe. You'll have to test to make sure. If you're making the call to the API directly, you should get a similar response.

As for why that access token isn't working, I'm honestly not sure why that is. Like I mentioned, we don't do anything with offline-access right now. It's something we're planning for future releases, which is why we are saving the token. We've heard of other users using it for offline access though. Logging out should not invalidate the token to our knowledge. The token should stay valid for at least a few hours regardless of whether the user is logged into your site.

You can use Facebook's Graph Explorer to test access tokens and different calls to see what the response is directly. That may help diagnose some problems and see errors more clearly as well:
developers.facebook.com/tools/explorer

Let us know if that helps you narrow down the issue,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 11 months ago #24151 by rajkum
Alex,

Thanks for your response.Can you please tell me exactly where in jfbconnect source code i can implement this functionality to parse the response.

Rajneesh
The topic has been locked.
Support Specialist
13 years 11 months ago #24215 by alzander
Rajneesh,
Sorry for the delayed response. We've done some investigation and have some code changes that should help you. The update below will fetch a 'long-lived' access token from Facebook that will be valid for the user for 60 days. Please note though, if the user changes their password or de-authorizes your app, the token will immediately be invalidated though.

Please edit the /components/com_jfbconnect/controllers/loginregister.php file. Around line 294, you'll see:
if ($token && $token != $fbClient->getApplicationAccessToken()) // Should always be valid, but caution is good.
                              $userMapModel->updateUserToken($jUserId, $token);
Replace that block of code with the following:
if ($token && $token != $fbClient->getApplicationAccessToken()) // Should always be valid, but caution is good.
                {
                    // get an extended access token
                    $params['client_id'] = $jfbcLibrary->facebookAppId;
                    $params['client_secret'] = $jfbcLibrary->facebookSecretKey;
                    $params['grant_type'] = 'fb_exchange_token';
                    $params['fb_exchange_token'] = $token;

                    $ch = curl_init();
                    $opts = array();
                    if ($configModel->getSetting('facebook_curl_disable_ssl', false))
                        $opts[CURLOPT_SSL_VERIFYPEER] = false;

                    $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
                    $opts[CURLOPT_URL] = 'https://graph.facebook.com/oauth/access_token';
                    $opts[CURLOPT_RETURNTRANSFER] = true;

                    curl_setopt_array($ch, $opts);
                    $response = curl_exec($ch);
                    curl_close($ch);

                    $response_params = array();
                    parse_str($response, $response_params);
                    if (isset($response_params['access_token']))
                    {
                        $newToken = $response_params['access_token'];
                        $userMapModel->updateUserToken($jUserId, $newToken);
                    }
                }
That update will exchange the short-lived (~2 hour) token that is normally provided with the long-lived one for 2 months. The JFBConnect user-map table will be updated with the new token so that you can use whatever code you already have to grab the token from the DB and use it.

Please test and let us know how that goes. a similar update will be in the 4.4 release (August/September timeframe). It will be coded very differently, but will have the same effect of storing the long-lived token in the db for the user.

If you need anything else, just let us know!

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

None
13 years 11 months ago #24249 by rajkum
Alex,
Thanks for your response. But i am looking for a function in JFBConnect source code where you can call the facebook api for the first time to request the permission for the Facebook application and in case user denied or allow the facebook application, i will parse the response (permission denied in case user does not allow)
and will call the appropriate function.

Please reply ASAP, because i have left only with few days to deliver my module.

Thanks
Rajneesh
The topic has been locked.
Support Specialist
13 years 11 months ago #24252 by alzander
Rajneesh,
You can do something like:
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$permissions = $jfbcLibrary->api('/me/permissions');
That should return a huge list of permissions the user has granted for your application. You can test how the data is returned from the page below:
developers.facebook.com/tools/explorer?m...ath=me%2Fpermissions

If you're simply looking to add code when the user logs in (which is also where we create the user in some cases), that functionality is all in the /components/com_jfbconnect/controllers/loginregister.php file. Mainly, you'd want to look at the login() function.

Hope that helps, but again, if you need something else, please let us know. If you're more specific about exactly what you're trying to do, that may help make sure we give you the exact answer you need as well.

Thanks,
Alex
The topic has been locked.