Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

r2581@opsdev009 (orig r129645): lshepard | 2008-11-03 11:26:04 -0800

 updating with the latest changes. we had a bad revision in there, but it's corrected now.
 
 ------------------------------------------------------------------------
 r128560 | lshepard | 2008-10-27 13:44:32 -0700 (Mon, 27 Oct 2008) | 17 lines
 
 Make the run around use the new methods
 
 Summary: Bring the sample code in line with the new APIs allowed in r128269.
 
 Test Plan: Tested the Run Around both before and after these changes, on IE6/7 and FF/Safari Mac. Worked fine for logging in and publishing feed.
 
 Revert: OK
 
 ------------------------------------------------------------------------
 r128374 | brent | 2008-10-24 15:50:53 -0700 (Fri, 24 Oct 2008) | 9 lines
 
 updating The Run Around to use fb:login-button's new onlogin attribute
 
 Reviewed By: lshepard
 
 Test Plan: the page still refreshes after login
 
 Revert: OK
  • Loading branch information...
commit 764d1f248e3717c0c8440011a6a66f7e16fb7928 1 parent e1685ef
(no author) authored
View
52 samples/therunaround/fbconnect.js
@@ -15,7 +15,7 @@
function facebook_onload(already_logged_into_facebook) {
// user state is either: has a session, or does not.
// if the state has changed, detect that and reload.
- FB_Call(function() {
+ FB.ensureInit(function() {
FB.Facebook.get_sessionState().waitUntilReady(function(session) {
var is_now_logged_into_facebook = session ? true : false;
@@ -32,40 +32,18 @@ function facebook_onload(already_logged_into_facebook) {
}
/*
- * "Session Ready" handler. This is called when the facebook
- * session becomes ready after the user clicks the "Facebook login" button.
- * In a more complex app, this could be used to do some in-page
- * replacements and avoid a full page refresh. For now, just
- * notify the server the user is logged in, and redirect to home.
- *
- * @param link_to_current_user if the facebook session should be
- * linked to a currently logged in user, or used
- * to create a new account anyway
+ * Our <fb:login-button> specifies this function in its onlogin attribute,
+ * which is triggered after the user authenticates the app in the Connect
+ * dialog and the Facebook session has been set in the cookies.
*/
-function facebook_button_onclick() {
-
- FB_Call(function() {
- FB.Facebook.get_sessionState().waitUntilReady(function() {
- var user = FB.Facebook.apiClient.get_session() ?
- FB.Facebook.apiClient.get_session().uid :
- null;
-
- // probably should give some indication of failure to the user
- if (!user) {
- return;
- }
-
- // The Facebook Session has been set in the cookies,
- // which will be picked up by the server on the next page load
- // so refresh the page, and let all the account linking be
- // handled on the server side
-
- // This could be done a myriad of ways; for a page with more content,
- // you could do an ajax call for the account linking, and then
- // just replace content inline without a full page refresh.
- refresh_page();
- });
- });
+function facebook_onlogin_ready() {
+ // In this app, we redirect the user back to index.php. The server will read
+ // the cookie and see that the user is logged in, and will deliver a new page
+ // with content appropriate for a logged-in user.
+ //
+ // However, a more complex app could use this function to do AJAX calls
+ // and/or in-place replacement of page contents to avoid a full page refresh.
+ refresh_page();
}
/*
@@ -82,7 +60,7 @@ function refresh_page() {
* Prompts the user to grant a permission to the application.
*/
function facebook_prompt_permission(permission) {
- FB_Call(function() {
+ FB.ensureInit(function() {
FB.Connect.showPermissionDialog(permission);
});
}
@@ -95,7 +73,7 @@ function facebook_prompt_permission(permission) {
*/
function facebook_publish_feed_story(form_bundle_id, template_data) {
// Load the feed form
- FB_Call(function() {
+ FB.ensureInit(function() {
FB.Connect.showFeedDialog(form_bundle_id, template_data);
//FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, FB.FeedStorySize.shortStory, FB.RequireConnect.promptConnect);
@@ -112,7 +90,7 @@ function facebook_publish_feed_story(form_bundle_id, template_data) {
* not connected, and shows the checkbox if that's true.
*/
function facebook_show_feed_checkbox() {
- FB_Call(function() {
+ FB.ensureInit(function() {
FB.Connect.get_status().waitUntilReady(function(status) {
if (status != FB.ConnectState.userNotLoggedIn) {
// If the user is currently logged into Facebook, but has not
View
3  samples/therunaround/lib/display.php
@@ -114,6 +114,9 @@ function render_footer() {
$html = '</div>' .
'<div class="footer_stuff">This is an awesome running app.</div>';
+ // the init js needs to be at the bottom of the document, within the </body> tag
+ // this is so that any xfbml elements are already rendered by the time the xfbml
+ // rendering takes over. otherwise, it might miss some elements in the doc.
if (is_fbconnect_enabled()) {
$html .= render_fbconnect_init_js();
}
View
30 samples/therunaround/lib/fbconnect.php
@@ -1,23 +1,17 @@
<?php
/*
- * Facebook-specific functions.
- */
-
-/*
* Renders the JS necessary for any Facebook interaction to work.
*/
function render_fbconnect_init_js() {
$html = sprintf(
'<script src="%s/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>
- <script type="text/javascript">FB_Init("'.get_api_key().'", "xd_receiver.php");
- FB_Call(function() {
- FB.FBDebug.logLevel = 4;
- FB.FBDebug.isEnabled = true;
- });
+ <script type="text/javascript">
+ FB.init("%s", "xd_receiver.php");
</script>
<script src="fbconnect.js" type="text/javascript"></script>',
- get_static_root());
+ get_static_root(),
+ get_api_key());
$already_logged_in = facebook_client()->get_loggedin_user() ? "true" : "false";
onloadRegister(sprintf("facebook_onload(%s);", $already_logged_in));
@@ -27,17 +21,23 @@ function render_fbconnect_init_js() {
/*
* Render a custom button to log in via Facebook.
- * When the button is clicked, the facebook_button_onclick JS function is fired.
- * That triggers the Facebook JS library to authenticate the user, and sets up
- * a handler for when the authentication is complete.
+ * When the button is clicked, the Facebook JS library pops up a Connect dialog
+ * to authenticate the user.
+ * If the user authenticates the application, the handler specified by the
+ * onlogin attribute will be triggered.
*
* @param $size size of the button. one of ('small', 'medium', 'large')
*
*/
function render_fbconnect_button($size='medium') {
+
+return '<a href="#" onclick="FB.Connect.requireSession(); return false;" >
+ <img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif" alt="Connect"/>
+</a>';
+
return '<fb:login-button '.
- 'size="'.$size.'" background="light" length="long" '.
- 'onclick="facebook_button_onclick();"></fb:login-button>';
+ 'size="'.$size.'" background="light" length="long" '.
+ 'onlogin="facebook_onlogin_ready();"></fb:login-button>';
}
/*
Please sign in to comment.
Something went wrong with that request. Please try again.