Topic-icon Social Plugins: code is confusing

Active Subscriptions:

None
10 years 5 months ago - 10 years 5 months ago #38280 by fb_100000157901698
In the absence of an API manual, I am trying to update my social plugins code to work with 5.1.2., but it is confusing to me

At:
class plgSocialProfilesWebteer extends SocialProfilePlugin
{
	function socialProfilesOnLogin($socialNetwork, $jUserId, $scUserId) 
...

This is working ok:
if ($socialNetwork == 'facebook') {
	$fields=array(
		'name',
		'first_name',
		'last_name',
		'email',
		'birthday_date',
		'sex',
		'current_location'
	);			
	$profileLibrary = new JFBConnectProfileFacebook();
	$profiledata=$profileLibrary->fetchProfile($scUserId, $fields);

But when I try to do the same thing with Google:
if ($socialNetwork == 'google') {

	$fields=array(
		'name',
		'email',
		'birthday',
		'gender',
		'currentLocation'
	);

	$profileLibrary = new JFBConnectProfileGoogle();
	$profiledata=$profileLibrary->fetchProfile($scUserId, $fields);

I have errors like "PHP Fatal error: Call to a member function isAuthenticated() on a non-object in /components/com_jfbconnect/libraries/profile/google.php on line 93" or "PHP Fatal error: Call to a member function getPeople() on a non-object in /components/com_jfbconnect/libraries/profile/google.php on line 129" (if I remove the request for field "email").

I also noticed this:
class JFBConnectProfileFacebook extends JFBConnectProfile
class JFBConnectProfileGoogle extends JFBConnectProfile

But you have this on /libraries/profile.php
//DEPRECATED class as of 5.1
class JFBConnectProfile

HELP! What should I use???
Last edit: 10 years 5 months ago by fb_100000157901698.
The topic has been locked.
Support Specialist
10 years 5 months ago #38291 by alzander
The deprecation line in there is an accident. That has been removed in the next release, sorry about that.

The reason you're getting those errors is because you shouldn't instantiate the profile library classes directly as that won't be setting everything up properly. Please use:
$profileLibrary = JFBCFactory::provider('google')->profile;
Our factory class will properly setup your auth, provider and other objects that are required to be set and injected into the profile library.

I hope that helps get you going, but if not, let me know.

Thanks,
Alex
The topic has been locked.
Support Specialist
10 years 5 months ago #38292 by alzander
Just so you don't think we're crazy, the thing that was deprecated was the older JFBConnectProfileLibrary class, which is what we used before v5.1. Since we added multiple providers, we needed class names with proper naming to avoid confusion.

Thanks,
Alex
The topic has been locked.