使用graph api访问组事件时,如何获取当前facebook访问令牌?

使用graph api访问组事件时,如何获取当前facebook访问令牌?,facebook,facebook-graph-api,Facebook,Facebook Graph Api,我有这段代码用于访问和显示来自Facebook群组的Facebook事件。如果您使用当前的access_令牌,则此操作有效,但access_令牌的有效期仅为一小时左右。每次加载页面时,我需要添加哪些代码以编程方式获取当前访问令牌 我看过facebook的建议,它让我的页面进入了一个永久的循环 <?php header ('Content-type: text/html; charset=utf-8'); $limit

我有这段代码用于访问和显示来自Facebook群组的Facebook事件。如果您使用当前的access_令牌,则此操作有效,但access_令牌的有效期仅为一小时左右。每次加载页面时,我需要添加哪些代码以编程方式获取当前访问令牌

我看过facebook的建议,它让我的页面进入了一个永久的循环

            <?php
            header ('Content-type: text/html; charset=utf-8');
            $limit = 5;

            $group_id = '68663437095';
            $url1 = 'https://graph.facebook.com/'.$group_id;
            $des = json_decode(file_get_contents($url1));


            $url2 = "https://graph.facebook.com/68663437095/events?access_token=CAACEdEose0cBAORQs8KFqo6Fw1ZA78alt8CgH3pyKgEVWdbsxWmBhjwVqOOSqst51fb1ZCHK0Dtz8CmTDCZByqoJMoaXcEU6qjN4IO1JWExSwuHzVRmNU5JEkzpdcSuhPd8StyYSObAhXU4DKngmnHtvF018wZAmsg8GEFXNatcZAZBBMbJmsUOvwSOa7DubIZD";
            $data = json_decode(file_get_contents($url2));
            ?>

            <style type="text/css">
                 .wrapper {
             width:200px;
             border:1px solid #ccc;
             font-family: "lucida grande",tahoma,verdana,arial,sans-serif;
             background-color: black;
             float:left;
             }

             .top {
             margin:5px;
             border-bottom:2px solid #e1e1e1;
             float: left;
             width:290px;
             }

             .single {
             margin:5px;
             border-bottom:1px dashed #e1e1e1;
             float:left;
             }

             .img {
             float:left;
             width:60px;
             text-align:center;
             margin:5px 5px 5px 0px;
             border-right:1px dashed #e1e1e1;
             }

             .text {
             width:220px;
             float:left;
             font-size:10px;
             }

             a {
             text-decoration: none;
             color: #3b5998;
             }
            </style>

            <div style="width: 250px; padding-bottom:15px;"><br/>
                <div style="width: 190x;  margin-left:15px;">
                    <a target="_parent" style="font-size:40px;" href="http://www.facebook.com/groups/fumcbixby/"> <?=$des->name?></a>
                    <div style="width:100%; margin: 5px">
                        <?=$des->description?>
                    </div>
                </div><br/>
                <?
                $counter = 0;

                foreach($data->data as $d) {
                    if($counter==$limit)
                    break;
                ?>
                <div style="width: auto; background-color:white; margin-left:15px; margin-bottom:15px; padding:5px">
                    <div style="float: left; width:120px;">
                        <img src="https://graph.facebook.com/<?= $d->id?>/picture">
                    </div>
                    <div>
                        <h2>Name <?= $d->name?></h2>
                        <h3>Location <?= $d->location?></h3>
                        <p>Start<?= date('F j, Y H:i',strtotime($d->start_time))?></p>
                        <p>End<?= date('F j, Y H:i',strtotime($d->end_time))?></p>
                        <a href= "https://www.facebook.com/events/<?= $d->id?>/?suggestsessionid=fc8548e2f42ad507b812ce9e80189592">Visit Event</a>
                    </div>
                </div>
                <?
                $counter++;
                }
                ?>
            </div>

.包装纸{
宽度:200px;
边框:1px实心#ccc;
字体系列:“lucida grande”,tahoma,verdana,arial,无衬线;
背景色:黑色;
浮动:左;
}
.顶{
保证金:5px;
边框底部:2个实心#e1e1;
浮动:左;
宽度:290px;
}
.单身{
保证金:5px;
边框底部:1px虚线#e1e1;
浮动:左;
}
.img{
浮动:左;
宽度:60px;
文本对齐:居中;
保证金:5px 5px 5px 0px;
右边框:1px虚线#e1e1;
}
.文本{
宽度:220px;
浮动:左;
字体大小:10px;
}
a{
文字装饰:无;
颜色:#3b5998;
}


id?>/图片“> 名称 位置 开始

结束


获取有效期为60天的扩展访问令牌

https://graph.facebook.com/oauth/access_token?             
client_id=APP_ID& 
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN  
将APP\u ID、APP\u SECRET和现有的\u访问\u令牌放入上述url并发出HTTP请求。 HTTP请求将返回JSON数组。然后您可以轻松解析扩展访问令牌

看看这个问题