Talk:PHP

From Facebook Developer Wiki

Jump to: navigation, search

Contents

[edit] Services_Facebook

Is there any usable documentation to Services_Facebook?

Failing to use functions as Users.hasAppPermission and Users.setStatus in the official PHP5 library I turned to the PEAR one but to no success. Is it a complete replacement for the official one or an addition? If the later, how do I combine them? I'm pretty lost on this one.

--1788332054 07:29, 28 May 2009 (PDT)

Facebook doesn't offer any documentation on Services_Facebook, as it's an unofficial community project (Facebook didn't add any of the Pear documentation to this article). I imagine you've already checked the Pear site? Pete (563683308 14:21, 28 May 2009 (PDT))

Someone should clean up the nasty code examples. --560880114 07:57, 7 November 2007 (PST)

What's up with the usage example? Isn't it completely wrong? ;) --610496754 15:47, 7 July 2008 (PDT)

[edit] Pathetic documentation

I had absolutely horrible time trying to figure out how to use the 'official' library, especially facebook_desktop.php Most of my problems have to do with implementation of login. Documentation re how to use the library for this purpose essentially does not exists. Trying to follow the recipe in general API section of this wiki runs into all sorts of traps that were set up by well-wishing creator of the library. For my desktop application I need to have my own server in turn talks to facebook.com. My own server should not support any interactive use, it is purely a service. So I am trying to follow the desktop model. 1. Desktop asks my service for login url. Service calls facebook.auth.createToken and returns http://www.facebook.com/login.php?api_key='[key]'&v=1.0&auth_token=[token] to desktop. 2. Desktop opens a browser with this url and has user going authorize the application. 3. Desktop calls the service with just used token. On the server side I can't manage to get the session. Neither calling get_session(), nor do_get_session(), nor require_login() works.

Already spent an incredible amount of time trying to implement authentication but to no avail. Very frustrated. The similar task for flickr was an considerably easier. At this point I am ready to drop the attempts to use the 'official' php library and try my luck with unofficial Services_Facebook.

Have you read Login Desktop App? -- Pete (563683308 13:32, 26 November 2008 (PST))

[edit] bad test app

Could someone please update this test app so that is actually works with the most recent API? I've already had to make one change, and trying to figure out the other problem.


[edit] bad Smiley App as well...

Looks like there is a file missing:

Warning: main(constants.php): failed to open stream: No such file or directory in /Smiley/index.php on line 6

Warning: main(): Failed opening 'constants.php' for inclusion (include_path='.:/usr/local/lib/php') in /Smiley/index.php on line 6

Warning: main(LIB_PATHmoods.php): failed to open stream: No such file or directory in /Smiley/index.php on line 7

Warning: main(): Failed opening 'LIB_PATHmoods.php' for inclusion (include_path='.:/usr/local/lib/php') in /Smiley/index.php on line 7

Warning: main(LIB_PATHdisplay.php): failed to open stream: No such file or directory in /Smiley/index.php on line 8

Warning: main(): Failed opening 'LIB_PATHdisplay.php' for inclusion (include_path='.:/usr/local/lib/php') in /Smiley/index.php on line 8

Fatal error: Call to undefined function: get_fb() in/Smiley/index.php on line 11

All I did was download all of the files, and upload them to my PHP5 compliant Linux server. Pretty frustrating using an out of the box example app, that doesn't work...

Where is the documentation for how to use the PHP Library, I cant find that. Lots of examples, but there is now documentat that lists all the functions available, with inputs etc.

Try API. -- Pete (563683308 12:24, 2 February 2009 (PST))
API helps with the documentation, but doesn't address the fact that the Smiley sample app is broken out of the box. Missing files all over. -- Alison
We realize Smiley is in need of an update. We're working on it. Thanks, Pete (563683308 10:48, 30 April 2009 (PDT))

[edit] (WAMP) PHP For Windows

I'm deploying my own server using a WAMP configuration instead of a LAMP one. Are these instructions and files good for PHP developed and deployed on Windows? ~Rhys -- (1164355928)

Update: The pear example is a bad one as although the code worked with few modifications, it appeared not to because user_info for all supplied test users was empty. Request permission to edit this page so it can be updated with a more worthwhile basic example so less people get lost. Just a thought! ~Rhys -- (1164355928)

Hi Rhys, as I announced recently, the main namespace for the wiki is locked down for edits by people outside of Facebook. Feel free to include your changes here, and I'll be glad to update the article with them. Sorry for the management layer here, but maintaining the content was becoming untenable. Thanks for offering to help clarify things in this article, I appreciate that. Pete -- 563683308 16:52, 13 November 2009 (PST)
Thanks Pete, nice to meet you :-) I read the post previously and was aware things were being locked down and the necessity of doing so. I'm happy to contribute and am working on some worthwhile documentation. ~Rhys -- (1164355928 22:24, 15 November 2009 (PST))
Thanks for updating that, Pete. Since someone's listening, I'll post more code as I solve problems here and there. ~Rhys --
Sure thing, Rhys. I'll keep an eye out for changes. And if I happen to miss one, feel free to ping me on my Talk page. Pete

(pdameasap 15:36, 16 November 2009 (PST))

[edit] Updated PEAR Code (WAMP Server)

More verbose code for this page:

<!-- App needs to be set as FBML in application settings for this to work --> <!-- For simplicity, this requires the user to add the application before continuing --> <!-- See: http://wiki.developers.facebook.com/index.php/Fb:if-is-app-user --> <!-- If the user is an app user, then do everything --> <!-- Otherwise, skip to the end for similar FBML redirecting to add application page --> <fb:if-is-app-user> <?php // One of the main usages of PEAR is so the include following this note will work unaltered // If it doesn't, then you either have a problem with your PEAR installation, or // your PEAR directory is not in your server's path, or you have not installed the // Services_Facebook PEAR module into your server. // NOTE: as of this writing Validate is required for Services_Facebook yet this package // is not listed as a dependency for Services_Facebook; this is a known error. // This is a listing of my PEAR packages after installing this and other basic packages: /* C:\Users\Owner>pear list INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET: ========================================= PACKAGE VERSION STATE Archive_Tar 1.3.3 stable Auth_SASL 1.0.3 stable Console_Getopt 1.2.3 stable DB 1.7.13 stable HTML_Template_IT 1.2.1 stable Image_GraphViz 1.2.1 stable Log 1.11.5 stable MDB2 2.4.1 stable MDB2_Driver_mysql 1.4.1 stable Mail 1.1.14 stable Net_SMTP 1.3.3 stable Net_Socket 1.0.9 stable PEAR 1.9.0 stable PEAR_Frontend_Web 0.7.4 beta Services_Facebook 0.2.8 alpha Structures_Graph 1.0.3 stable Validate 0.8.2 beta XML_Util 1.2.1 stable */ // Your exact packages may vary, especially since my test installation is a WAMP one... // Of particular note is that PEAR itself may need to be updated; use the following command to do so: // pear install --alldeps PEAR // Also note that some packages (including Services_Facebook and Validate) are either alpha or beta // These packages need to be installed while the system is in the corresponding state like: // pear config-set preferred_state beta // pear install --alldeps Validate // pear config-set preferred_state alpha // pear install --alldeps Services_Facebook // pear config-set preferred_state stable // The previous comments should serve to underscore that there are potentially a lot of things // that can go wrong with getting to the point where you can use this test code. require_once 'Services/Facebook.php'; // Set globals Services_Facebook::$apiKey = 'xxx'; Services_Facebook::$secret = 'xxx'; try { $api = new Services_Facebook(); // See: http://wiki.developers.facebook.com/index.php/Authorizing_Applications // Shows all information passed to us via get echo "Get variables:<br />"; print_r($_GET); echo "<br /><br />"; // Shows all information passed to us via post echo "Post variables:<br />"; print_r($_POST); echo "<br /><br />"; // Shows all variables passed to us from the server (probably not needed, but helpful) echo "Server variables:<br />"; print_r($_SERVER); echo "<br /><br />"; // If a session key is passed, then grab it if (!empty($_POST)) { if (!empty($_POST["fb_sig_session_key"])) { $api->sessionKey = $_POST["fb_sig_session_key"]; // This next line is just for debugging echo "Obtained session key: " . $api->sessionKey . "<br />"; echo "This means we may use methods which require a session key.<br /><br />"; } } if (!empty($_POST)) { echo "We have been given post data.<br />"; if (!empty($_POST["fb_sig_canvas_user"])) { $isCanvasUser = true; $uid = $_POST["fb_sig_canvas_user"]; echo "fb_sig_canvas_user says the user is a canvas user.<br />"; echo "Generally speaking, you won't be passed a session key, nor will you be able to<br />"; echo "use methods which need to be signed (so don't be surprised if you didn't get<br />"; echo "'fb_sig_session_key' passed to you).<br />"; echo "It may actually be impossible to see this message unless the surrounding FBML<br />"; echo "requiring that the application be authorized is removed, but this hasn't been<br />"; echo "tested exhaustively.<br />"; } else { $isCanvasUser = false; } if (!empty($_POST["fb_sig_user"])) { $isAddedUser = true; $uid = $_POST["fb_sig_user"]; echo "fb_sig_user says the user is an application user.<br />"; } else { $isAddedUser = false; } if ($isCanvasUser || $isAddedUser) { // We have the uid for the current user, so we can use it to get the user's friends $info = $api->users->getInfo($uid); echo "You are:<br />"; echo (string)$info->user->uid . ": "; echo (string)$info->user->first_name . " "; echo (string)$info->user->last_name . "<br /><br />"; // A list of friend uid's, can also be gotten from $_POST but we wouldn't be able to show a call $uids = $api->friends->get($uid); $fql = 'SELECT uid, first_name, last_name FROM user WHERE uid IN (' . implode(',', $uids) . ')'; $result = $api->fql->query($fql); $friendCount = 0; echo "Here are up to twenty of your friends: <br />"; foreach ($result->user as $user) { if ($friendCount>=20) break; // Print only users who have authorized their data; those who have not will have empty name data if (!empty($user->first_name)&&!empty($user->last_name)) { // Print with uids //echo (string)$user->uid . ": " . (string)$user->first_name . " " . (string)$user->last_name . "<br />"; // Print without uids, for individual user privacy echo (string)$user->first_name . " " . (string)$user->last_name . "<br />"; $friendCount++; } } } } } catch (Services_Facebook_Exception $e) { echo $e->getLastCall() . "<br />"; echo $e->getMessage(); } echo "<br />The page this page is coming back to after adding is:<br />"; echo "http://apps.facebook.com" . $_SERVER['PHP_SELF'] . "&canvas=<br />"; ?> <!-- See: http://wiki.developers.facebook.com/index.php/Authorizing_Applications --> <fb:else> <fb:redirect url="http://www.facebook.com/login.php?v=1.0&api_key=<?php echo Services_Facebook::$apiKey; ?>&next=http://apps.facebook.com<?php echo $_SERVER['PHP_SELF']; ?>&canvas="/> </fb:else> </fb:if-is-app-user>

~Rhys -- (pdameasap 00:48, 16 November 2009 (PST))

[edit] Updates

Is there any RSS feed or mailinglist where it's mentioned when this Library gets updated? Or could you provide a public svn repos for it? (718577434 07:40, 20 August 2009 (PDT))

The SVN repo is linked at the top of the article: http://svn.facebook.com/svnroot/platform/clients/packages/facebook-platform.tar.gz
Please read Facebook Platform Support Resources for the various ways you can keep up with what's new on Facebook Platform.
Pete (563683308 11:30, 20 August 2009 (PDT))
reference