去接朋友' 来自 Facebook 个人资料的生日

发布于 2024-07-30 17:15:07 字数 232 浏览 5 评论 0原文

我想从用户的 Facebook 个人资料(提供他们的 Facebook 凭据)中获取我网站上用户及其朋友的“生日”。

他们是 Facebook API/Connect 中的一项功能吗?我可以使用它在使用 Facebook API 的原生 Facebook 应用程序上尽可能从 facebook 获取这些详细信息。

我想将这些数据存储在我的数据库中,在此之前,将要求用户提供他们的 Facebook 凭据并同意。

I want to fetch 'birthdays' of users, and their friends on my website, from their facebook profiles (with their facebook credentials supplied).

Is their a feature in Facebook API/Connect that I can use to fetch these details from facebook as possible on Native Facebook Apps using Facebook API.

I want to store this data in my DB, and users will be asked for their facebook credentials and consent before this is done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

朦胧时间 2024-08-06 17:15:07

阅读api文档这样的事情很容易完成。 你可以这样做:

$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
}

Read the api documentation things like this are easily done. You can do it like this:

$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
}
尸血腥色 2024-08-06 17:15:07

所以最近我想检查一下我的朋友,看看他们中是否有人今天过生日。 使用 FQL 这非常简单,我鼓励您更多地探索 FQL,因为它将产生比 Pierre 好心提供的解决方案更有效的解决方案。 这是代码的一小段:

$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 />";
 }

So recently I wanted to check my friends to see if any of them had their birthday for the current day. Using FQL this is super easy and I encourage you to explore FQL more because it will yield a more efficient solution than, say, what Pierre kindly offered. Here is a small snippet of the code:

$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 />";
 }
素衣风尘叹 2024-08-06 17:15:07

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 一次执行多个调用。 检查 Facebook API。


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;
}

Do something like that or use the Batch API to do multiple calls at once. Check the Facebook API.

故事和酒 2024-08-06 17:15:07

您可以通过 API 获取它,但 Facebook 的条款严格禁止您在数据库中存储除用户 ID 之外的任何内容 - 请参阅 开发者维基了解详细信息。 您每次都需要查询 API。

You could fetch it via the API, but Facebook's terms strictly forbid you from storing anything other than their user ID in your database - see the developer wiki for details. You will need to query the API each time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文