Topic-icon 3rd-Party Subscription Integration

Support Specialist
10 years 9 months ago #34444 by alzander
learnthrusong,
Sorry for the (very) delayed response on this and thanks for providing the solution you're working with. If you already have the overrides in Akeeba how you want, but haven't made it to the fetching of user profile data, I can help with that. It should be quite simple, actually.

The following code lets you instantiate our profile library and then fetch data from Facebook about the user:
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $jfbcLibrary->getFbUserId(); // Get the Facebook ID of the user
$profileLibrary = JFBConnectProfileLibrary::getInstance();
$profile = $profileLibrary->fetchProfile($fbUserId, array(0 => 'first_name', 1 => 'last_name'));

$firstName = $profile->get('first_name'); // this gets the first name of the user.
Once you have that $profile variable, you can use the data to populate stuff however you want. You can look at the /components/com_jfbconnect/libraries/profile.php file for a list of fields, though there are actually more that Facebook supports.

I hope that helps and thanks again for sharing.

Tim,
If you're still needing help in pulling in the profile, let us know. I know you mention that you found a good roundabout way to do it, which I think should work just fine as well. If you need anything though, that's what we're here for.

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

None
10 years 9 months ago #34541 by learnthrusong
Hi Alex,

Brilliant - thanks...

I have an update to post regarding this which drastically changes the approach due to akeeba's Framework on Framework (FOF) having provided hooks into the controllers. I will update the post asap to reflect this change.

Thanks again,

Gez
The topic has been locked.
Active Subscriptions:

None
10 years 9 months ago - 10 years 9 months ago #34575 by learnthrusong
OK Guys, after some experimentation with the method described in my post above ( 34095 ), it was not 'the' answer.

After opening up a discussion with Nicholas over at akeeba about alternative ways of being able to 'inject' the facebook data from JFBC (same for jLinked), it transpired that there was only 1 viable option: extending FoF to include some plugin hooks. Very quickly, said 'hooks' have been added.

You can access this FoF functionality by
  1. Downloading & installing the latest dev release
  2. Create a system plugin
  3. Create the following method: ** UPDATED **
    public function onBeforeAkeebasubsControllerLevelRead(FOFController &$controller, FOFInput &$input)
    {
           // instance JFBC class
           $jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
           $fbUserId = $jfbcLibrary->getFbUserId(); // Get the Facebook ID of the user 
           $profileLibrary = JFBConnectProfileLibrary::getInstance(); 
           $profile = $profileLibrary->fetchProfile($fbUserId, array(0 => 'first_name', 1 => 'last_name', 2 => 'name',  3 => 'email'));
    
            // Get the akeebasubs view object
            $view = $controller->getThisView(); 
           // print_r($view); // to see the elements/properties ($view->cache is what you'll be most interested in)
    
            // array to push facebook data into
            $cache = array();
    
            $cache['email'] = $profile->get('email'); // where $profile is your FB profile object
            /* ... any other FB data here ... */
            $cache['name'] = $profile->get('name');
    
            // Overwrite the elements of $view->cache (that you want to populate with FB data - E.G. in a loop
            $overwriteKeys = array_keys($cache); // the array keys we'll want to overwrite in the $view->cache
            foreach($view->cache as $k => $v){
                 // if the key ($k)  is one that we're populating with data from FB
                 if(in_array($k, $overwriteKeys)){
                      // set the matched element within $view->cache to the data from $cache array 
                      $view->cache[$k] = $cache[$k];  // E.G. $view->cache['email'] = $cache['email'];
                 } //end if
            }//end foreach
    }
  4. Done ;) ** END UPDATE **
Hope it helps!

Gez
Last edit: 10 years 9 months ago by learnthrusong.
The topic has been locked.