• Somebody can help me. When I setup webhook on my fb app. I entered callback URL https://iconofficial.com/wp-admin/admin-ajax.php?action=message and verify token ‘9fDZwm9QRG2TL8i1aqXTernmZBa74mOw’
    It return bad request 400, url couldn’t be validated
    And this is my code to verify:

    add_action( 'admin_post_message', array( $this, 'facebook_return' ) );
    add_action( 'admin_post_nopriv_message', array( $this, 'facebook_return' ) );
    
    public function facebook_return() {
     $hub_verify_token = null;
     $verify_token     = '9fDZwm9QRG2TL8i1aqXTernmZBa74mOw';
     if ( isset( $_REQUEST['hub_mode'] ) && $_REQUEST['hub_mode'] == 'subscribe' ) {
    	$challenge        = $_REQUEST['hub_challenge'];
    	$hub_verify_token = $_REQUEST['hub_verify_token'];
    	if ( $hub_verify_token === $verify_token ) {
    		header( 'HTTP/1.1 200 OK' );
    		echo $challenge;
    		die;
    		}
    	}
    }
    • This topic was modified 5 years, 3 months ago by thanhtd.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    If you POST to /wp-admin/admin-post.php instead, your code should work as is. If you need to use admin-ajax.php for some reason, your action hooks should be wp_ajax_message and wp_ajax_nopriv_message.

    • This reply was modified 5 years, 3 months ago by bcworkz. Reason: wrong hook
    Thread Starter thanhtd

    (@thanhtd)

    oops, sorry, because wp_ajax_message and wp_ajax_nopriv_message not working so I change to test with admin-post.php, I forgot change back to wp_ajax_message and wp_ajax_nopriv_message when I post this topic. However, when I use admin-ajax.php, admin-post.php or register_router (api). It is not working

    • This reply was modified 5 years, 3 months ago by thanhtd.
    Moderator bcworkz

    (@bcworkz)

    I tested the admin-post.php version of your code on my site and it works as expected. The equivalent Ajax version wouldn’t change the callback behavior. Full disclosure: I did change it from class to procedural style, but otherwise the same. And I used GET instead of POST to pass values.

    The problem lies beyond the posted code. Where did you put the add_action() calls in your class? They belong in the class constructor __construct(). Be sure your class is instantiated somewhere. Use your browser’s network developer tool to ensure the passed values are properly formed.

    Thread Starter thanhtd

    (@thanhtd)

    Thanks for your help. I think, have a problem with my customer server because everything work perfect on my server (may be facebook block my customer domain,…).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘facebook webhook request via ajax’ is closed to new replies.