How to get Users Email Id in Facebook application using PHP?

前端 未结 3 1476
感情败类
感情败类 2020-12-28 23:04

I have created a simple Facebook application in PHP, that greets user by there user name, I also want there Email id, to be displayed. But i am not able to do that. the code

3条回答
  •  再見小時候
    2020-12-28 23:40

    You can get the Email Address, directly without using the FQL.

    // initialize facebook
     $facebook = new Facebook(array(
            'appId' => APP_ID,
            'secret' => APP_SECRET));
    
     $session = $facebook->getSession();
     if ($session) {
     try {
        $fbme = $facebook->api('/me');
      } catch (FacebookApiException $e) {
        error_log($e);
      }
    }
    else
    {
      echo "You are NOT Logged in";
    }
    
    //getting the login page if not signned in
    if (!$fbme) {
      $loginUrl = $facebook->getLoginUrl(array('canvas' => 1,
                                          'fbconnect' => 0,
                                          'req_perms' =>                   'email,user_birthday,publish_stream',
                                          'next' => CANVAS_PAGE,
                                          'cancel_url' => CANVAS_PAGE ));
     echo '';
     } else {
    
          // $fbme is valid i.e. user can access our app
         echo "You can use this App";
     }
    
     // getting the profile data
     $user_id = $fbme[id];
     $name=$fbme['name'];
     $first_name=$fbme['first_name'];
     $last_name=$fbme['last_name'];
     $facebook_url=$fbme['link'];
     $location=$fbme['location']['name'];
     $bio_info=$fbme['bio'];
     $work_array=$fbme['work'];
     $education_array=$fbme["education"];
     $email=$fbme['email'];
     $date_of_birth=$fbme['birthday'];
    

    This code worked for me..and i go all the information needed with the Email ID.

    NOTE: User has to allow us to get their Information during the Approval of Application.
    

提交回复
热议问题