Вот мой код. (строка json содержит список событий для любого пользователя. Идентификатор пользователя передается в URL-адресе как user=xxxxxx).
Интерактивный URL-адрес находится здесь http://livemuzik. co.uk/fb3.php
Код:
Код: Выделить всё
include('fb/src/facebook.php');
if ($_REQUEST["user"]){
$user_id = $_REQUEST["user"];
} else $user_id = "me";
$app_id = "xxxxxxxxxxx";
$app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$my_url = "http://livemuzik.co.uk/fb2.php";
$code = $_REQUEST["code"];
if(empty($code)) {
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=create_event,user_events,friends_events";
echo("top.location.href='" . $auth_url . "'");
}
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;
$access_token = file_get_contents($token_url);
// GET JSON DATA FOR EVENTS
$events_url = "https://graph.facebook.com/";
$events_url .= $user_id;
$events_url .= '/events?fields=id,owner&limit=100&';
$events_url .= $access_token;
$json = file_get_contents($events_url,0,null,null);
var_dump(json_decode($json, true));
// foreach(json_decode($json) as $obj) {
// Need to work out what code to put in here or what else I can do to output the json information as single variable values from an array
// }
Код: Выделить всё
array(2) {
["data"] => array(8) {
[0] => array(4) {
["id"] => string(15) "159231904144232"
["owner"] => array(2) {
["name"]=> string(11) "Dean Hurley"
["id"]=> string(10) "1038439076"
}
["start_time"]=> string(24) "2011-07-15T04:00:00+0000"
["rsvp_status"]=> string(9) "attending"
}
[1]=> array(4) { ["id"]=> string(15) "118572044893404" ["owner"]=> array(3) { ["name"]=> string(9) "RAVEOLOGY" ["category"]=> string(13) "Musician/band" ["id"]=> string(10) "8443998018" } ["start_time"]=> string(24) "2011-07-10T04:00:00+0000" ["rsvp_status"]=> string(6) "unsure" } [2]=> array(4) { ["id"]=> string(15) "123371994410260" ["owner"]=> array(3) { ["version"]=> int(1) ["name"]=> string(23) "The Bozeat City Rollers" ["id"]=> string(15) "182725898429985" } ["start_time"]=> string(24) "2011-07-03T04:00:00+0000" ["rsvp_status"]=> string(9) "attending" } [3]=> array(4) { ["id"]=> string(12) "316743171061" ["owner"]=> array(2) { ["name"]=> string(17) "Richard Johnstone" ["id"]=> string(9) "668431151" } ["start_time"]=> string(24) "2011-07-01T23:00:00+0000" ["rsvp_status"]=> string(6) "unsure" } [4]=> array(4) { ["id"]=> string(15) "160599624007096" ["owner"]=> array(2) { ["name"]=> string(11) "Dean Hurley" ["id"]=> string(10) "1038439076" } ["start_time"]=> string(24) "2011-06-15T08:30:00+0000" ["rsvp_status"]=> string(9) "attending" } [5]=> array(4) { ["id"]=> string(15) "231851770163680" ["owner"]=> array(2) { ["name"]=> string(11) "Dean Hurley" ["id"]=> string(10) "1038439076" } ["start_time"]=> string(24) "2011-06-13T08:30:00+0000" ["rsvp_status"]=> string(9) "attending" } [6]=> array(4) { ["id"]=> string(15) "203743706335174" ["owner"]=> array(2) { ["name"]=> string(15) "Bozeat Red Lion" ["id"]=> string(12) "155723533443" } ["start_time"]=> string(24) "2011-06-09T16:00:00+0000" ["rsvp_status"]=> string(9) "attending" } [7]=> array(4) { ["id"]=> string(15) "208151712549353" ["owner"]=> array(3) { ["name"]=> string(20) "Blackbush Promotions" ["category"]=> string(13) "Musician/band" ["id"]=> string(12) "336182297448" } ["start_time"]=> string(24) "2011-06-05T02:30:00+0000" ["rsvp_status"]=> string(6) "unsure" } } ["paging"]=> array(2) { ["previous"]=> string(181) "https://graph.facebook.com/1038439076/events?fields=id%2Cowner&limit=100&access_token=331843765383|b9ef3b78db6a708b1a735347.1-1038439076|DkL44VVbAPlHl8mb03P1WA9VF_o&since=1310702400" ["next"]=> string(181) "https://graph.facebook.com/1038439076/events?fields=id%2Cowner&limit=100&access_token=331843765383|b9ef3b78db6a708b1a735347.1-1038439076|DkL44VVbAPlHl8mb03P1WA9VF_o&until=1307241000" } }
Подробнее здесь: https://stackoverflow.com/questions/632 ... reach-loop