Topic-icon Ability to link a Facebook page to the profile viewed ?

Active Subscriptions:

None
Well I have beginning to link JFConnect to Facebook and we would like to have some kind of an application working for all Facebook users.

Basically we want to have a Facebook page tab url which is linked to the Facebook profile viewed. For instance if the Facebook profile viewed is member of our website we would like to show index.php?option=com_comprofiler&task=userprofile&user=xxxx where xxxx is the id of the Facebook user on our website.

And if the Facebook visited profile is not a member of our website, we would like a default yyyy user to be showed.

Would you have any idea of how to achieve this automatically ?

Thanks for idea
The topic has been locked.
Support Specialist
Jean Claude,
What you say should be very do-able, but will take a little bit of code changes (below) and tinkering. I haven't tested what I wrote below, but hopefully, it will 'just work'. We'll see..

In the /components/com_jfbconnect/libraries/canvas.php file is where all changes need to be made. This is what sets up the Page Tab view. Around line 119, you'll see:
$tabTemplate = $this->configModel->getSetting('canvas_tab_template');
                        $app->setTemplate($tabTemplate);
Try changing that too:
        $mappedFbUserId = $this->jfbcLibrary->getFbUserId();
        $userMapModel = new JFBConnectModelUserMap();
        $jUserId = $userMapModel->getJoomlaUserId($mappedFbUserId)
        if ($jUserId && (JRequest::getCmd('option') != 'com_comprofiler' || JRequest::getCmd('user') != $jUserId)) // FB user has a profile on the Joomla site
            $app->redirect('index.php?option=com_comprofiler&task=userprofile&user='.$jUserId);
        else if (!$jUserId && (JRequest::getCmd('option') != 'com_comprofiler' || JRequest::getCmd('user') != 'yyyy')) // Fixed profile, no FB user on Joomla site
            $app->redirect('index.php?option=com_comprofiler&task=userprofile&user=yyyy');

        $tabTemplate = $this->configModel->getSetting('canvas_tab_template');
        $app->setTemplate($tabTemplate);
Whew.. again, untested. Please turn on Error reporting and turn GZip off in the Global Configuration area. That will let any errors show. If there are any, let us know, and we can go from there to tweak it further.

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

None
14 years 5 months ago #16663 by activha
Well I tried and I have a parse error : Parse error: syntax error, unexpected T_IF in /var/.../canvas.php on line 124 which is
if ($jUserId && (JRequest::getCmd('option') != 'com_comprofiler' || JRequest::getCmd('user') != $jUserId)) // FB user has a profile on the Joomla site

By the way, would this work also if the Facebook user adds our application to one of its page instead of a profile, will we retrieve also its credentials ?

Thanks
The topic has been locked.
Support Specialist
Jean,
For that error above, the line before it is missing a ; at the end:
$jUserId = $userMapModel->getJoomlaUserId($mappedFbUserId);
Hopefully, that's the only issue with the code, but let us know if you run into other errors.

As for credentials for Pages that add your application, no, you wouldn't get the Pages credentials. Pages don't, themselves, have credentials. They have admins which 'own' them. You'd need those admins to login through your site, and accept the permissions you require from Facebook, to be able to get any of their information.

Good luck,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 5 months ago #16675 by activha
Oupss sorry did not even see the missing ; :-(
Thanks...

Your code is working, however is there a possibility for a redirect once thing instead of a perpetual redirect ? I have problems when redirecting to CB profiles in which I have ajax tabs getting other urls, looks like a loop or something equivalent.

Thanks
Jean Claude

PS : by the way is this the code for the VIEWED Facebook page ? I mean will it display the VIEWED CB Facebook profile for a regular Facebook user and also for a joomla user viewing the CB Facebook page ?
The topic has been locked.
Support Specialist
Wow! Always glad to hear a block of code works on the first try :)

For only doing it once and letting users navigate away, try the following:
$profileRedirect = $jSession->get('jfbcProfileRedirect', true);
if ($profileRedirect)
{
   $jSession->set('jfbcProfileRedirect', false);
   $mappedFbUserId = $this->jfbcLibrary->getFbUserId(); 
   .... all the other code here own to the $app->redirect
}
$tabTemplate = $this->configModel->getSetting('canvas_tab_template'); 
$app->setTemplate($tabTemplate);

Hopefully, that's all you need. Either way, definitely let us know how that goes!
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 5 months ago #16703 by activha
Nice it avoids loops and allow users to navigate away on the same application, so the menu is now working. It seems that we may have a problem with the reveal page which reappears when I come back to the initial page, maybe a session cookie deleted also by the code.

And now, how could it be possible for users to retrieve the initial page. I mean that people will see the initial page, then navigate through other pages and at some time would like to come back to the initial page. How can I set this up ?

Is it possible to have a dynamic menu link which will always bring back to the initial page of the viewed Facebook/page profile ? which brings me to other questions,

if this is a page, will the Facebook userid still be used to show the user initial page ?

is the initial page really the page of the VIEWED page on Facebook if it is mapped on our website ? I mean if the Facebook user navigates through other pages in Facebook including our app, will our initial page show different pages according to the userid of the viewed Facebook pages ?
The topic has been locked.
Support Specialist
Jean Claude,
Do you have (or are you) a PHP developer? The main reason I ask is that we can help you try to implement new features, but can't always debug everything as every site and requirement is different.

I'm honestly not sure why the reveal page would show again. What do you mean by "Come back to the initial page".. is this while navigating within the Tab, and does the user already Like the Page? The code I gave above would only work if either the Reveal Page feature is disabled OR the user has already Like'd the Page. If not, the reveal page should be shown, and the redirecting to the profile stuff shouldn't happen at all actually.

To come back to the initial page, that'd have to be something you do in your Joomla site. Create a PHP module, or something similar with an item that says "Return home" and dynamically figure out what "Home" should be. You could, in that module, simply clear the session variable 'jfbcProfileRedirect' and it should return the user back to the main page, but I can't guarantee there wouldn't be other issues.

I'm not sure what you mean by:

if this is a page, will the Facebook userid still be used to show the user initial page ?


I believe all the info you're asking is basically what happens if the user goes to different FB Pages with your app installed, what will happen. The answer would be that we'll re-check if the user has Like'd the Page first, and show the Reveal page if not. Then, I believe, we'll do the profile redirect I provided above. If the user ever navigated off that page, it would go to whatever the default Page Tab is (since the profile redirect would be skipped). You'd really need to test this as, again, this isn't normal JFBConnect operation, so all I can do is help where I can. I'm not implementing this or testing it at all.

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

None
14 years 5 months ago #16743 by activha

alzander wrote: Do you have (or are you) a PHP developer?

Well I am not a PHP developer but I have basic skills to correct basic things I think.
Would you know someone that you could recommend for special adaptations ? Or could you provide it yourself for special requests ?

alzander wrote: I believe all the info you're asking is basically what happens if the user goes to different FB Pages with your app installed, what will happen. The answer would be that we'll re-check if the user has Like'd the Page first, and show the Reveal page if not..

This is fine but what I would like to know is if JFBConnect can check whether the FB Page on which our app is installed is linked to a user in Joomla ?
What I mean is : is there a mapping somewhere also for the FB Pages to retrieve the user to whom it belongs and check if it is a user in our Joomla ? I understand that it works for FB Profiles , but would it work for FB Pages also ?

Thanks for helping Alex

This is new and pretty difficult learning curve
The topic has been locked.
Support Specialist
No, there's no way for JFBConnect to know about the admins of a Facebook Page. Facebook doesn't work that way. We should be able to detect the Page ID (I think), but the admin info about that page isn't available. Additionally, a Page can be 'owned' by many users (admins), so there's not a 1-to-1 relationship between a FB Page and users, even if we could retrieve the admin list (it may be possible, but just don't know off-hand).

Hope that makes sense. Yes, FB can be very daunting at times, especially when it comes to users, apps, and Pages. JFBConnect takes a lot of the pain out, when we do what you want.. going beyond that means learning a lot of what we do behind the scenes to make things easier, as well as figuring out what you want to do :)

Good luck,
Alex
The topic has been locked.