douqianxian7008 2017-05-16 12:25
浏览 45

在Facebook Graph API中传递电子邮件和用户生日范围

I am new in Facebook Graph API..

I am using this code and it is fetching name and gender perfectly. I want to get email and date of birth from facebook.

<?php
 // added in v4.0.0
   require_once 'autoload.php';
   use Facebook\FacebookSession;
   use Facebook\FacebookRedirectLoginHelper;
   use Facebook\FacebookRequest;
   use Facebook\FacebookResponse;
   use Facebook\FacebookSDKException;
   use Facebook\FacebookRequestException;
   use Facebook\FacebookAuthorizationException;
   use Facebook\GraphObject;
   use Facebook\Entities\AccessToken;
   use Facebook\HttpClients\FacebookCurlHttpClient;
   use Facebook\HttpClients\FacebookHttpable;

   // init app with app id and secret
   FacebookSession::setDefaultApplication( 'xxxxxx','xxxxxxxxxxxxxxxxxx' );

   // login helper with redirect_uri
   $helper = new FacebookRedirectLoginHelper('http://www.xxxxxxxxx.com/' );

   try {
      $session = $helper->getSessionFromRedirect();
   }catch( FacebookRequestException $ex ) {
      // When Facebook returns an error
   }catch( Exception $ex ) {
      // When validation fails or other local issues
   }

   // see if we have a session
   if ( isset( $session ) ) {
      // graph api request for user data
      $request = new FacebookRequest( $session, 'GET', '/me' );
      $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
      $femail = $graphObject->getProperty('email');      // To Get Facebook email ID

      /* ---- Session Variables -----*/
      $_SESSION['FBID'] = $fbid;
      $_SESSION['FULLNAME'] = $fbfullname;
      $_SESSION['EMAIL'] =  $femail;

      /* ---- header location after session ----*/
      header("Location: index.php");
   }else {
      $loginUrl = $helper->getLoginUrl();
      header("Location: ".$loginUrl);
   } 

?>

Now how I pass email and user birthday scope in my code. I already take the approval of User birthday and email from facebook viva my APP.

  • 写回答

1条回答 默认 最新

  • dongli7870 2017-05-16 16:03
    关注
    $permissions = ['email', 'user_birthday'];
    $loginUrl = $helper->getLoginUrl('http://{your-website}/login-callback.php', $permissions);
    

    Source: https://developers.facebook.com/docs/php/FacebookRedirectLoginHelper/5.0.0

    Btw, the redirect URL is a required parameter anyway.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端