WordPress.org

Ready to get started?Download WordPress

Forums

Facebook AWD All in one
[resolved] WordPress as "App on Facebook" (14 posts)

  1. limsi31
    Member
    Posted 1 year ago #

    Quick question please..
    I perfer my wordpress to be an app within facebook on canvas and I woud like to know how can I change the code so it's possible to request the authorization to as worpress as app, for example as per code below..

    // If the user has not installed the app, redirect them to the Auth Dialog
    if (!$user) {
    $loginUrl = $facebook->getLoginUrl(array(
    'scope' => $scope,
    'redirect_uri' => $app_url,
    ));

    Where specifically should I implement this?
    Thanks and great work!!

    http://wordpress.org/extend/plugins/facebook-awd/

  2. AHWEBDEV
    Member
    Plugin Author

    Posted 1 year ago #

    Hi, a method in the $AWD_facebook exists to force the login.
    So you do not need to use the code you post.

    Open the function.php file in your theme, and add thoses lines

    function force_fb_login()
    {
    	//access to the Facebook AWD object
    	global $AWD_facebook;
    	//Check if the user is logged in with Facebook, if no, redirect him to the Facebook login page.
    	$AWD_facebook->login_required();
    }
    add_action('init', 'force_fb_login');
  3. AHWEBDEV
    Member
    Plugin Author

    Posted 1 year ago #

    Try it and tell me, i will update the plugin to work 100% with canvas

  4. limsi31
    Member
    Posted 1 year ago #

    OMG..that what SOOO fast ! thanks...
    will update you shortly and thanks again!!

  5. AHWEBDEV
    Member
    Plugin Author

    Posted 1 year ago #

    If it works, you can use write it with less code...

    global $AWD_facebook;
    add_action('init', array($AWD_facebook, 'login_required');

    In fact i am not sure this will work, because the redirect is set to the current url. but in an app canvas the current url is the app page, but for the plugin the current url is the WP url.

    Try it, and tell me.

  6. limsi31
    Member
    Posted 1 year ago #

    Nope.. sorry..pasted it on in the function.php file of the default template..(twentyeleven)...and it gave me a blank page..
    I pasted it at the bottom as the last function.
    any additional suggestions?
    thx

  7. limsi31
    Member
    Posted 1 year ago #

    well...not working yet..:)

  8. AHWEBDEV
    Member
    Plugin Author

    Posted 1 year ago #

    Ok, i know why, when the file functions.php is read, the $AWD_facebook is not yet an object.
    However i saw that in the code the redirect url of this function after the login will be your website url, not the fb app url.

    So I wrote a little hack, in wait of a new version of the plugin.

    function force_fb_login()
    {
    	//access to the Facebook AWD object
    	global $AWD_facebook;
    	//define the app url and the redirect after login
    	$redirect_uri = $AWD_facebook->options['app_infos']['link'] . (get_option('permalink_structure') != '' ? '?' : '&') . 'redirect_to=' . $AWD_facebook->get_current_url();
    	$scope = $AWD_facebook->options["perms"];
    	$login_options = array(
    		'scope' => $scope,
    		'redirect_uri' => $redirect_uri
    	);
    	//Check if the user is logged in with Facebook, if no, redirect him to the Facebook login page.
    	if (!is_user_logged_in()) {
    		echo '<script>top.location.href="'.$AWD_facebook->fcbk->getLoginUrl($login_options).'";</script>';
    		exit();
    	}
    }
    add_action('wp_head', 'force_fb_login');

    I tested it, and it works great in app canvas !

  9. limsi31
    Member
    Posted 1 year ago #

    Hey there!
    ONE BIG THANKS TO YOU!!
    I have implemented the hack..on the functions.php file..but I get "please try again later...

    this is the URL that I get...
    https://www.facebook.com/dialog/oauth?client_id=310966989000738&redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fapps%2Fapplication.php%3Fid%3D310966989000738%26redirect_to%3Dhttp%3A%2F%2Flocalhost%2Fwordpress%2F&state=ae8857103431921703f85adef65d539a&scope=email

    any ideas?
    Thx. AGain..

  10. AHWEBDEV
    Member
    Plugin Author

    Posted 1 year ago #

    So this one !

    function force_fb_login()
    {
    
    	//access to the Facebook AWD object
    	global $AWD_facebook;
    	//define the app url and the redirect after login
    	$redirect_uri = 'https://apps.facebook.com/'.$AWD_facebook->options['app_infos']['namespace'].'/?redirect_to=' . $AWD_facebook->get_current_url();
    	$scope = $AWD_facebook->options["perms"];
    	$login_options = array(
    		'scope' => $scope,
    		'redirect_uri' => $redirect_uri
    	);
    	//Check if the user is logged in with Facebook, if no, redirect him to the Facebook login page.
    	if (!is_user_logged_in()) {
    		echo '<script>top.location.href="'.$AWD_facebook->fcbk->getLoginUrl($login_options).'";</script>';
    		exit();
    	}
    }
    add_action('wp_head', 'force_fb_login');
  11. limsi31
    Member
    Posted 1 year ago #

    I owe you!!
    Thanks for the code and the smile of success!!!
    Highly appreciated!
    Limor

  12. gamerarenade
    Member
    Posted 1 year ago #

    I have added the latest code into my functions.php file, but this redirects me everytime to: https://www.facebook.com/dialog/oauth?client_id=299495103493495&redirect_uri=https%3A%2F%2Fapps.facebook.com%2F%2F%3Fredirect_to%3Dhttp%3A%2F%2Fgamer-arena.de%2F&state=2812be0baa75fa2330038bb659c9d651&scope=email

    and it says, that it is an problem, and cant connect with it.

    Can you help me? Or is this a problem from my theme?

  13. gamerarenade
    Member
    Posted 1 year ago #

    and its say also this:

    API Error Code: 191
    API Error Description: The specified URL is not owned by the application
    Error Message: Invalid redirect_uri: Die Anwendungseinstellungen lassen die angegebene URL nicht zu.

    Sry for my bad english ^^

  14. AHWEBDEV
    Member
    Plugin Author

    Posted 1 year ago #

    @gamerarenade That means the redirect url is not specified in the allowed url of facebook connect settings on facebook side.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic