Plugin Development – Facebook Integration for User Login and Join
-
I’m relatively a noob when it comes to PHP development, but I’ve done well in the past doing simple data input, output, and correlation projects. In my current project, I need to create the ability for users to join groups headed by a leader. There are three phases of this project, which are:
1. Create an interface to manage leaders (each leader may have zero, one, or more groups they lead)
2. Create an interface to manage groups (every group must have a leader defined)
3. Create a method for anybody (with a facebook account) to join a group (any one person could be associated with multiple groups)Thus far, I’ve completed phases one and two. I’m now at the point where I’m trying integrate the Facebook PHP SDK as a web application (via Facebook) and associate Facebook users to a group. To do this, I’ve created a WordPress post and added a shortcode tag to it to call my program. The solution only appears to half work.
The “login” option is shown on the page and when clicked, appropriately asks for permission for my site to access the user’s information. When the user clicks okay… it simply goes back to the post but the login link continues to show rather than show give me data to act on.
My code for this portion of the plugin is as follows:
<?php function fcm_fb() { include('facebook-php-sdk/src/facebook.php'); session_start(); //facebook application $config['appid' ] = "##############"; $config['secret'] = "##############"; // Create our Application instance. $facebook = new Facebook(array( 'appId' => $config['appid'], 'secret' => $config['secret'], 'cookie' => true, )); $user = $facebook->getUser(); $loginUrl = $facebook->getLoginUrl( array( 'scope' => 'email' ) ); if ($user) { try { //get user basic description $userInfo = $facebook->api("/$user"); $fb_access_token = $facebook->getAccessToken(); echo "Name: " . $userInfo['name']; } catch (FacebookApiException $e) { //you should use error_log($e); instead of printing the info on browser error_log('APP ERROR: '.$e); $user = null; } } if (!$user) { echo 'Please <a href="' . $loginUrl . '">login.</a>'; } } add_shortcode( 'fcmreg', 'fcm_fb' ); ?>I think the problem is that Facebooks redirect points it to the following URL, which isn’t being properly parsed by the program:
http://www.fitnesschallenges.net/p90x/?code=AQAqd2fO6UGOz-8hK7-SNxXTmjuPgy7PMhtOh-HMRvxE2hnsQRCMWk5UQY9zI8BtSxBtHv1vrleCDLXOYPMYPQTO_vjz_qdA53zHToQHQI_-Mx44VWtBp4aanXuGZs3zGJhNVRvWGogFj4Vdt_biOHNVxGAICAn1XpZZWw3WfDHgSLJShTXAYNbXutgiRq0h7UykXVpByo8yicuXS_iF406Qk0rkqU14aHVPH4pkc-iss-R0wCSsDyCG2bsEbJ0khQP-HUdNz6PSZGdyxyzhxw-9_7ci77YAfYYAXiXOzMWRjHev_MQmEN5HLVog_gllxZk&state=d96abbef137d32a8d4bf2a9719471675#_=_The URL of the post is:
http://www.fitnesschallenges.net/p90x/
Also, when I attempted to use this code outside of Facebook it did work… which is why I think it has to do with the post data not being properly parsed…. just no idea how to fix that.
Any thoughts or suggestions?
The topic ‘Plugin Development – Facebook Integration for User Login and Join’ is closed to new replies.