简体   繁体   English

facebook获得用户生日

[英]facebook get user birthday

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

This uses PHP SDK v4, not v5, however I found it easier to follow, and this persons tutorial is fantastic. 这使用PHP SDK v4,而不是v5,但是我发现它更容易理解,这个人教程非常棒。 http://www.krizna.com/demo/login-with-facebook-using-php/ 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,如果您按照以下方式更新它,您可以获得性别(仍在学习自己,所以不确定其他字段适用于这些步骤)

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. IF BLANK中的行,不显示字段。

    In the FBConfig.php file, update the following: 在FBConfig.php文件中,更新以下内容:

    // 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. 生日对我不起作用,但我认为这可能是由于一些原因,例如需要额外的权限,我隐藏了我的等等。希望这会有所帮助。

  • 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. 要阅读用户详细信息,您需要使用PHP facebook API,可以从Facebook免费下载。

    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/

    Your app must request the user_birthday (or friends_birthday ) permission in order to get this. 您的应用必须请求user_birthday (或friends_birthday )权限才能获得此权限。

    Reference: 参考:

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM