php facebook获取用户生日

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6012958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:09:23  来源:igfitidea点击:

facebook get user birthday

phpfacebook

提问by Jeremy Gwa

All,

全部,

I have been struggling to retrieve a users birthday, via PHP.

我一直在努力通过 PHP 检索用户生日。

I look on the net and all the examples given do not work, or have been depreciated.

我在网上看,所有给出的例子都不起作用,或者已经折旧了。

what is the code to get a users birthday ...eg. Year day month ?

获得用户生日的代码是什么......例如。年日月?

some clear code would be useful

一些清晰的代码会很有用

regards,

问候,

Jer

杰尔

回答by ifaour

This uses PHP SDK v4, not v5, however I found it easier to follow, and this persons tutorial is fantastic. http://www.krizna.com/demo/login-with-facebook-using-php/

这使用 PHP SDK v4,而不是 v5,但是我发现它更容易遵循,而且这个人的教程很棒。 http://www.krizna.com/demo/login-with-facebook-using-php/

They explain how to retrieve EMAIL in the comments, and if you update it as follows you can get GENDER (Still learning myself so not sure what other fields applies to these steps)

他们在评论中解释了如何检索 EMAIL,如果您按如下方式更新它,您可以获得 GENDER(仍在学习自己,所以不确定哪些其他字段适用于这些步骤)

In your index.php, update the following:

在您的 index.php 中,更新以下内容:

<?php if ($_SESSION['FULLNAME'] !="") { 
?>
    <li class="nav-header">Name</li>
    <li><?php echo $_SESSION['FULLNAME']; ?></li>
<?php
} ?>


<?php if ($_SESSION['EMAIL'] !="") { 
?>
    <li class="nav-header">Email</li>
    <li><?php echo $_SESSION['EMAIL']; ?></li>
<?php
} 
?>




<?php if ($_SESSION['GENDER'] !="") { 
?>
    <li class="nav-header">Gender</li>
    <li><?php echo $_SESSION['GENDER']; ?></li>
<?php
} 
?>

The above code looks slightly different from the demo code because I wrapped the

上面的代码看起来与演示代码略有不同,因为我包装了

  • lines in an IF BLANK, do not display field.

    In the FBConfig.php file, update the following:

    // see if we have a session

    if ( isset( $session ) ) {
        // graph api request for user data
        // $request = new FacebookRequest( $session, 'GET', '/me' );
        $request = new FacebookRequest( $session, 'GET', '/me?locale=en_US&fields=id, name, email, gender, birthday' );
        $response = $request->execute();
        // get response
        $graphObject = $response->getGraphObject();
        $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
        $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
        $fbemail = $graphObject->getProperty('email');    // To Get Facebook email ID
        $fbgender = $graphObject->getProperty('gender');    // To Get Facebook gender ID
        $fbbirthday = $graphObject->getProperty('birthday');    // To Get Facebook birthday ID
    
    
        /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
        $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $fbemail;
        $_SESSION['GENDER'] =  $fbgender;
        $_SESSION['BIRTHDAY'] =  $fbbirthday;
    

    Birthday isn't working for me like this, but I believe it might be for a few reasons such as additional permissions are needed, I have mine hidden, etc. Hope this helps.

  • IF BLANK 中的行,不显示字段。

    在 FBConfig.php 文件中,更新以下内容:

    // 看看我们是否有会话

    if ( isset( $session ) ) {
        // graph api request for user data
        // $request = new FacebookRequest( $session, 'GET', '/me' );
        $request = new FacebookRequest( $session, 'GET', '/me?locale=en_US&fields=id, name, email, gender, birthday' );
        $response = $request->execute();
        // get response
        $graphObject = $response->getGraphObject();
        $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
        $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
        $fbemail = $graphObject->getProperty('email');    // To Get Facebook email ID
        $fbgender = $graphObject->getProperty('gender');    // To Get Facebook gender ID
        $fbbirthday = $graphObject->getProperty('birthday');    // To Get Facebook birthday ID
    
    
        /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
        $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $fbemail;
        $_SESSION['GENDER'] =  $fbgender;
        $_SESSION['BIRTHDAY'] =  $fbbirthday;
    

    生日对我来说不是这样,但我相信这可能是出于一些原因,例如需要额外的权限,我隐藏了我的权限等。希望这会有所帮助。

  • 回答by AjayR

    You should have the login button code which should look like

    你应该有登录按钮代码,它应该看起来像

    <fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
    

    To read the user details, you need to use PHP facebook API which can be downloaded freely from Facebook.

    要阅读用户详细信息,您需要使用可从 Facebook 免费下载的 PHP facebook API。

    The following link will explain you clearly further.

    以下链接将进一步为您解释清楚。

    http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/

    http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/

    回答by no.good.at.coding

    Your app must request the user_birthday(or friends_birthday) permission in order to get this.

    您的应用程序必须请求user_birthday(或friends_birthday)权限才能获得此权限。

    Reference:

    参考: