1

我需要你的帮助,因为我认为我已经达到了我的技能极限。我正在开发一个代码来使用图形 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);

到目前为止,我已经能够存储除喜欢之外的所有数据。在此先感谢您的帮助

4

1 回答 1

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_likesuser_id他们喜欢的每一页都是该表格中的page_id一行name

于 2012-11-28T19:05:44.110 回答