PHP 中的 Facebook JSON 解码事件

发布于 2024-12-02 19:02:16 字数 601 浏览 0 评论 0原文

我有:

$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']), true);


var_dump($user);

它工作正常并提供配置文件输出。

但是:

$events = json_decode(file_get_contents(
    'https://graph.facebook.com/me/events?access_token=' .
    $cookie['access_token']), true);


var_dump($events);

给出:

object(stdClass)#5 (1) { ["data"]=> array(0) { } }

我不确定这是否是一个空对象,或者我是否没有正确访问“数据”内部的内容。但是,我知道实际上有与我的个人资料相关的事件。权限已被授予,所以这不是问题。有人知道如何返回我的个人资料中的所有事件名称吗?

I have:

$user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']), true);


var_dump($user);

which works fine and gives profile output.

But:

$events = json_decode(file_get_contents(
    'https://graph.facebook.com/me/events?access_token=' .
    $cookie['access_token']), true);


var_dump($events);

gives:

object(stdClass)#5 (1) { ["data"]=> array(0) { } }

I'm not sure if this is an empty object, or if I'm not accessing what's inside 'data' correctly. But, I know there are in fact events associated with my profile. Permissions have been granted, so that's not the problem. Anyone know how to return all event names for my profile?

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

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

发布评论

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

评论(1

乱世争霸 2024-12-09 19:02:16

为了获取 PHP 中的事件,您必须按照以下步骤操作,

请求正确的访问令牌,请点击此链接
facebook:永久页面访问令牌?

替换下面文本 YOUR_ACCESS_TOKEN 字段中的访问令牌

    <?php
        $json_string = 'https://graph.facebook.com/5973249561/events/?access_token=YOUR_ACCESS_TOKEN&fields=id,name,description,start_time,place,cover,end_time&limit=999';
        $obj = json_decode(curl_get_contents($json_string),true);

        foreach ($obj['data'] as $key => $value) {
          echo @$value['id'];
          echo @$value['name'];
          echo @$value['start_time'];
          echo @$value['place'];
          echo @$value['cover']['source'];
        }

        function curl_get_contents($url)
        {
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         $data = curl_exec($ch);
         curl_close($ch);
         return $data;
       }
     ?>

In order to get events in PHP you have to follow these steps,

Request a proper Access Token follow this link
facebook: permanent Page Access Token?

Replace your Access token below texted YOUR_ACCESS_TOKEN field

    <?php
        $json_string = 'https://graph.facebook.com/5973249561/events/?access_token=YOUR_ACCESS_TOKEN&fields=id,name,description,start_time,place,cover,end_time&limit=999';
        $obj = json_decode(curl_get_contents($json_string),true);

        foreach ($obj['data'] as $key => $value) {
          echo @$value['id'];
          echo @$value['name'];
          echo @$value['start_time'];
          echo @$value['place'];
          echo @$value['cover']['source'];
        }

        function curl_get_contents($url)
        {
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         $data = curl_exec($ch);
         curl_close($ch);
         return $data;
       }
     ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文