Display a public Facebook event on a web page

試著忘記壹切 提交于 2019-12-08 07:26:05

问题


How can I show information from a specifiec Facebook event on a webpage?

Things like: time, location, created by, more info, and also the image used as thumbnail.

Even if I didn't created that event.

Someone else created it.

I just have the url of that Facebook event and I can find the user id of the person who created it.

I found this page: http://www.codeofaninja.com/2011/07/display-facebook-events-to-your-website.html

But it's not the same as I want, and I couldn't figure it out how to do it.

Any help is much appreciated.


回答1:


What languages do you program in? say php or javascript, and i will post a quick sample?

You can use one of the many SDK's but for me the 2 that are easiest to use are the php-sdk and javascript-sdk.

https://developers.facebook.com/docs/sdks/

Using either you can just send a request to the graph api to retrieve the info about the event by its id.

https://developers.facebook.com/docs/reference/api/

https://developers.facebook.com/docs/reference/api/event/

EDIT: Sample assumes php-sdk 3.1.1 is installed and initiated. Will show 8 of the most recent events added to page or app. App Access Token is required.

<?php 
$pageid='YourPageId.or.AppId';

$MEevents = $facebook->api('/'.$pageid.'/events?access_token='.$app_access_token.'&fields=id,name,from,start_time,location,end_time&limit=8');
echo '<div align="center" style="border: 0px solid; width: 100%;">';
foreach ($MEevents as $key=>$value) {
        $i=1;
        foreach ($value as $fkey=>$fvalue) {
        if($fvalue[id]==h){
        }else{
        $i++;   
        $whofrom = $fvalue[from];
        $whofromname = $whofrom[name];
        $whofrompic = $whofrom[id];

        echo '<div title="'.$fvalue[name].'" style="vertical-align: top; border: 1px inset; width: 700px; min-height: 80px; margin: 2px;">';
        echo '<div id=""></div>';
        echo '<div style="margin: 4px; padding: 3px; text-align: left;">';
        echo '<img src="https://graph.facebook.com/'.$fvalue[id].'/picture" style="float: left; clear: left; margin: 5px;">&nbsp;';
        echo '<a href="https://www.facebook.com/event.php?eid='.$fvalue[id].'" target="_blank">'.$fvalue[name].'</a><br />';
        echo 'Location: '.$fvalue[location].'<br />';
        echo 'Starts '.nicetime($fvalue[start_time]).' - Ends '.nicetime($fvalue[end_time]).'<br />';
        echo '</div>';
        echo '</div>';
            }

        }
    }
    echo '</div>';
 ?>


来源:https://stackoverflow.com/questions/7971990/display-a-public-facebook-event-on-a-web-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!