编程语言
首页 > 编程语言> > 在php中启用user_birthday权限facebook生日

在php中启用user_birthday权限facebook生日

作者:互联网

我正在制作一个Facebook应用程序来显示用户的生日………

     <?
         require_once('php-sdk/facebook.php');
         $config = array(
                          'appId' => 'YOUR_APP_ID',
                          'secret' => 'YOUR_APP_SECRET',
                         );

         $facebook = new Facebook($config);
         $user_id = $facebook->getUser();
     ?>
     <html>
     <head></head>
     <body>

     <?
            if($user_id) 
            {

                  // We have a user ID, so probably a logged in user.
                  // If not, we'll get an exception, which we handle below.
                  try 
                  {

                        $user_profile = $facebook->api('/me','GET');
                        echo "Name: " . $user_profile['name'];

                        // Birth Date to be printed here........
                       echo "DOB:  ".$user_profile['birthday'];
                  } 
                  catch(FacebookApiException $e) 
                  {
                       // If the user is logged out, you can have a 
                       // user ID even though the access token is invalid.
                      // In this case, we'll get an exception, so we'll
                      // just ask the user to login again here.
                     $login_url = $facebook->getLoginUrl(); 
                     echo 'Please <a href="' . $login_url . '">login.</a>';
                     error_log($e->getType());
                     error_log($e->getMessage());
                  }   
             } 
             else 
             {

                    // No user, print a link for the user to login
                    $login_url = $facebook->getLoginUrl();
                    echo 'Please <a href="' . $login_url . '">login.</a>';

              }
     ?>

     </body>
     </html>

现在,问题是这打印出如预期的名称但在出生日期没有任何打印…….当我进一步提及时,我听说了facebook权限(扩展)……
并从以下链接
http://developers.facebook.com/docs/reference/api/user/

我发现我们需要启用权限users_birthday或friends_birthday.

现在,我们如何在PHP代码中启用它?…请帮助样品…….
对不起,如果这个问题看起来很愚蠢.我只是facebook app开发中的新人,也是php的初学者…….
我尝试了stackoverflow.com中的其他示例,它对我帮助不大……

解决方法:

我没有看到您已阅读PermissionAuthentication文档的迹象;你不是要求用户允许他们访问他们的生日.

将user_birthday添加到范围时,将用户发送到Auth对话框,如果他们批准了权限,您将能够访问他们的生日.

您在“应用程序设置”中配置的权限仅适用于(已弃用)经过身份验证的引荐或App Center登录屏幕,您的应用程序需要明确要求所有其他登录流程中的权限

标签:php,facebook,facebook-graph-api,user-profile
来源: https://codeday.me/bug/20190613/1231913.html