0

在 URL 中提供访问令牌后,我使用 Facebook 开放图作为 json 提要格式来获取页面名称。

这是我的代码:

$get_pages = file_get_contents("https://graph.facebook.com/me/accounts?access_token=".$_POST['access_token']);
$get_pages = json_decode($get_pages);

foreach($get_pages->data as $page){
    echo $page[name];
    }

我试图呼应页面的名称。Facebook 提供的 Json 代码如下所示:

 {
       "data": [
          {
             "category": "website",
             "name": "jjj",
             "access_token": "jjj",
             "id": "jjj",
             "perms": [
                "jjj",
                "jjj",
                "jjj",
                "jjj",
                "jjj",
                "jjj"
             ]
          },
          {
             "category": "Community",
             "name": "ggg",
             "access_token": "ggg",
             "id": "ggg",
             "perms": [
                "ggg",
                "ggg",
                "ggg",
                "ggg",
                "ggg",
                "ggg"
             ]
          }
],
   "paging": {
      "next": "hhh"
   }
}

我收到此错误:

    catchable fatal error: object of class stdclass could not be converted to string in
with this line of code :$get_pages = json_decode($get_pages);

我在这里做错了什么?

4

1 回答 1

0

我解决了:) 我将代码更改为:

$get_pages = file_get_contents("https://graph.facebook.com/me/accounts?access_token=".$_POST['access_token']);
$get_pages = json_decode($get_pages, TRUE);
echo '<select id="select_page">';
foreach($get_pages[data] as $page_name){
echo '<option>'.$page_name[name].'</option>';
}
echo '</select>';
于 2013-02-12T22:22:51.593 回答