Topic-icon Code for Facebook Avatar

Active Subscriptions:

None
14 years 4 months ago #18864 by trawel
Is there a simple piece of code that I can drop into a module to display the User Photo for a person after they have logged into Facebook?

My settings are configured to pull new photos over every time a user logs in so that we always have the most recent photo for them.
The topic has been locked.
Support Specialist
14 years 4 months ago #18867 by alzander
Replied by alzander on topic Code for Facebook Avatar
If you're pulling the photo into one of the 3rd party systems (CB, JomSocial, Kunena, etc), you should use that system to show the photo. I can give you the code to show the photo for the user from Facebook, but that only works for user's that are logged in through JFBConnect... it wouldn't work user's that didn't login through Facebook. Additionally, you'd be pulling the avatar from Facebook, and not your own servers.

If you let me know what you're integrating with, I may be able to help.. you might need to look up how to do it from that extension though as well.

Alex
The topic has been locked.
Active Subscriptions:

None
14 years 4 months ago #18869 by trawel
Replied by trawel on topic Code for Facebook Avatar
Hi Alex,

I do have Community Builder installed but we only use CB to store basic information coming from the Open Graph so that we can try to understand our users better.

Facebook is the only way that users can login to our site. Because we are a real-life community website we felt that this would prevent people from posting anonymously. In a way we're forcing people to use their true identify (or at least their FB one) to interact with each other.

Given that information I believe using either the photo coming from FB at login or the CB one would work. Do you agree, or do you have other thoughts?

Tracy
The topic has been locked.
Support Specialist
14 years 4 months ago #18913 by alzander
Replied by alzander on topic Code for Facebook Avatar
Tracy,
I'm honestly not sure off-hand how to pull the avatar out of CB. If you're guaranteed that each user is logging in through Facebook to your site through JFBConnect, you can use the following block of code to always show their Facebook Avatar:
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$fbUserId = $jfbcLibrary->getMappedFbUserId();
$avatarURL = 'https://www.facebook.com/profile.php?id='.$fbUserId;
echo '<img src="'.$avatarURL.'" />';
Hope that helps, but if you have any questions or run into issues.. just let me know!

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

None
14 years 4 months ago #18936 by trawel
Replied by trawel on topic Code for Facebook Avatar
Alex,

The code you provided didn't pull the Facebook photo back but what it did do is provide the URL to the FB user's profile which turned out to be great for me. I had already wrote the code to retrieve the CB profile image. I then took the code you provided and wrapped it around the image tag to provide a link back to the user's FB profile by clicking the photo. Given all the help you've provided I thought I would share the final code in case it could help someone else. See the attachment.

The code I wrote calls a file named crop.php which is responsible for cropping the CB profile photo down to a constrained size of 32x32. Here is a URL where people can get the crop code. They should place it in a file titled crop.php and then put the file in their Joomla root directory.

www.toknowmore.net/e/1/php/crop-images-with-php.php

Thanks again for all of your help.
Tracy

get-cb-profile-photo.txt
The topic has been locked.
Support Specialist
14 years 4 months ago #18938 by alzander
Replied by alzander on topic Code for Facebook Avatar
Tracy,
Yup, that's definitely the link to the user's profile.. My bad.. but guess it's a good thing that that's what you were looking for! :)

Awesome for the code sharing. We definitely appreciate it, and will keep it in mind if others are looking for something similar.

Best of luck, and should you need anything else, just let us know.

Thanks,
Alex
The topic has been locked.