我需要你的帮助,因为我认为我已达到技能限制。 我正在开发一个代码,使用图形API从Facebook获取用户数据并将其存储到MYSQL数据库中。 到目前为止,我已经能够检索并存储除了喜欢的所有内容。
这里是代码:
function getUserData() {
$fb_cookie = $this->getCookie();
if($fb_cookie) {
$url = 'https://graph.facebook.com/me?access_token='.$this->getAccessToken();
$data = json_decode($this->getDataFromUrl($url));
$fb['id'] = $data->id;
$fb['first_name'] = $data->first_name;
$fb['last_name'] = $data->last_name;
$fb['email'] = $data->email;
$fb['likes'] = $data->likes;
$fb['hometown'] = $data->hometown->name;
//tokens
$fb['token'] = $fb_cookie['access_token'];
$fb['token_expires'] = $fb_cookie['expires'];
return $fb;
}
}
虽然我已获得许可" user_likes"在令牌中。仍无法存储或检索数据以将其保存到MYSQL中。
function update_members($criteria=array()) {
$fb_user_id = $criteria['fb_user_id'];
$fb_first_name = $criteria['fb_first_name'];
$fb_last_name = $criteria['fb_last_name'];
$fb_email = $criteria['fb_email'];
$fb_likes = $criteria['fb_likes'];
$fb_hometown = $criteria['fb_hometown'];
}
$sql = "INSERT INTO ".$GLOBALS['db_table']['members']."
(fb_user_id, first_name, last_name, fb_email, fb_likes, hometown)
VALUES ('$fb_user_id', '$fb_first_name', '$fb_last_name', '$fb_email', '$fb_likes', '$fb_hometown')";
$u1 = new MySqlTable();
$u1->executeQuery($sql);
到目前为止,我已经能够存储所有数据但是喜欢。 提前感谢您的帮助
答案 0 :(得分:1)
/me
来电不包含赞。
你将打电话给/me/likes
,它会返回如下内容:
{ "data": [
{
"name": "Hunger Games",
"category": "Book",
"id": "114531238562971",
"created_time": "2012-11-28T03:55:27+0000"
},
{
"name": "CivicRush",
"category": "Software",
"id": "160319707426901",
"created_time": "2012-11-27T01:53:40+0000"
},
...
]
}
请记住,表中的单个列不会包含所有喜欢的内容,除非您想用逗号分隔它们或将它们存储在json中。您需要另一个名为member_likes
的表user_id
,page_id
,name
等,他们喜欢的每个页面都是该表中的一行