Getting friends' birthday from facebook profile

I want to get the "birthdays" of users and their friends on my website from my facebook profiles (with the facebook credentials provided to them).

Is there a feature on Facebook API / Connect that I can use to get this information from facebook, as much as possible, on Native Facebook Apps using the Facebook API.

I want to save this data in my database, and users will be asked to confirm their credentials and consent with Facebook before this is done.

+3
source share
4 answers

Read the api documentation how easy it is to do. You can do it as follows:

$facebook = new Facebook( $apikey, $secret );
$uid = $facebook->require_login();

$friends = $facebook->api_client->friends_get(); // $friends is an array holding the user ids of your friends

foreach( $friends as $f ) {
    $data = $facebook->api_client->fql_query( "SELECT birthday_date FROM user WHERE uid=$f" );
    // $data[0] is an array with 'birthday_date' => "02/29/1904"
    // see api documentation for other fields and do a print_r
}
+4

, , . FQL , FQL , , , , , . :

$friends = $facebook->api_client->friends_get();
$uids = "";

foreach($friends as $f) {
  $uids .= "uid=$f OR ";
}

$query_uids = substr($uids,0,strlen($query_uids)-4);

date_default_timezone_set('UTC');
$current_date = date("m/d");
echo "<br />Searching for birthdays for the given month/day: $current_date<br />";

$data = $facebook->api_client->fql_query( "SELECT name, uid FROM user WHERE ( ($query_uids) AND strpos(birthday_date,'$current_date') >= 0 )" );

if(count($data) > 0) {
  foreach($data as $d) {
    print_r($d);
  }
} else {
 echo "<br />No Birthdays Today<br />";
 }
+4

require_once('facebook-platform/client/facebook.php');

$facebook = new Facebook(API_KEY, SECRET);
$facebook->require_login();

function getInfo($user_list, $fields) 
{
    try
    {
        $u = $facebook->api_client->users_getInfo($user_list, $fields);
        return $u;
    }
    catch (FacebookRestClientException $e)
    {
        echo $e->getCode() . ' ' . $e->getMessage();
    }
}

function getFriendsBirthdays($user_id) 
{
    $f = $_REQUEST['fb_sig_friends'];
    $f = explode(',', $f);
    $birthdays = array();
    foreach($f as $friend_id) 
    {
       $birthdays[] = getInfo($friend_id, 'birthday');
    }
    return $birthdays;
}

- Batch API . API Facebook.

+3

You can get it through the API, but the terms of Facebook strictly forbid you to store anything other than your user ID in your database - see the wiki developer for details. You will need to request an API each time.

+1
source

Source: https://habr.com/ru/post/1714598/


All Articles