facebook->getUser() returning 0

前端 未结 5 1511
天涯浪人
天涯浪人 2021-01-16 04:36

Whenever I try to login a prompt opens asking for the basic permissions, after that its being redirected to my redirect_uri with an URL

=\">http://loc

5条回答
  •  死守一世寂寞
    2021-01-16 04:57

    After several hours, the solution for me was (Let's say my site is http://www.site123.com):

    Settings @ https://developers.facebook.com

    1. App Domain: site123.com (even blank it will work though)
    2. Site URL: http://site123.com IMPORTANT : NOT http://www.site123.com

    PHP Code - fb_config.php

    //Declarations
    $app_id     = "{you AppID}";
    $app_secret = "{your App Secret}";
    $site_url   = "http://site123.com/receive_data_from_facebook.php";
    
    //New Facebook
    $facebook = new Facebook(array(
    'appId'     => $app_id,
    'secret'    => $app_secret,
    'cookie'    => TRUE, /* Optional */
    'oath'      => TRUE  /* Optional */
    ));
    
    //Login URL
    $loginUrl = $facebook->getLoginUrl(array(
        'scope'     => 'email,user_birthday',
        'redirect_uri'  => $site_url,
        ));
    
    //Get FacebookUserID
    $fbuser = $facebook->getUser();
    

    Important Note Also: I had some issues with Firefox $facebook->getUser() was 0 even my code was working on Chrome. But after cleaning Firefox cache, it worked nicely!

    Hope it helps.

提交回复
热议问题