-1

i want to get all attending events on my profile on Facebook. i found this interesting answer and i think that is what i need. Graph API - Get events by owner/creator

i copy and paste the code, and i change the app-id, the secret and the page, i launch the page but it says "Fatal error: Class 'Facebook' not found in /membri/bestparty/BPARTY4/index.php on line 25"

i included the Facebook php sdk v4 downloaded by github, without composer (yes, i read all the documentation about it, but i don't understand how it works) here is the code

<?php
require_once 'facebook-php-sdk-v4-4.0-dev/autoload.php';

use Facebook\FacebookRequest;
use Facebook\FacebookRequestException;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookServerException;
use Facebook\FacebookSession;


date_default_timezone_set('America/Los_Angeles');


    $app_id = '1508703399385376';
    $secret = 'c16169730c7dd504f2ba3a88b50e0888';
    $page_id = '1482914931991616';

    $config = array();
    $config['appId'] = $app_id;
    $config['secret'] = $secret;
    $config['fileUpload'] = false; // optional

    $facebook = new Facebook($config);

    $fql = 'SELECT 
                eid, 
                name, 
                pic_square, 
                creator,
                start_time,
                end_time
            FROM event 
            WHERE eid IN 
                (SELECT eid 
                    FROM event_member 
                    WHERE uid='.$page_id.'
                ) 
            AND end_time >= ' . mktime() . '
            ORDER BY start_time ASC
    ';

    $ret_obj = $facebook->api(array(
        'method' => 'fql.query',
        'query' => $fql,
    ));

    $html = '';                            
    foreach($ret_obj as $key)
    {
        $facebook_url = 'https://www.facebook.com/event.php?eid=' . $key['eid'];

        $start_time = date('M j, Y \a\t g:i A', $key['start_time']);
        $end_time = date('M j, Y \a\t g:i A', $key['end_time']);

        $html .= '
            <div class="event">
                <a href="'.$facebook_url.'">
                    <img src="'.$key['pic_square'].'" />
                </a>
                <span>
                    <a href="'.$facebook_url.'">
                        <h2>'.$key['name'].'</h2>
                    </a>
                    <p class="time">'.$start_time.'</p>
                    <p class="time">'.$end_time.'</p>
                </span>
            </div>
        ';
    }

    echo "$html a";
    echo "aaaa";



?>

i want also to know that it works also if i put my profile id, instead of page-id. thank you

Community
  • 1
  • 1
Andrea Loda
  • 19
  • 1
  • 4

1 Answers1

0

You appear to be mixing SDK 3 code with SDK 4. See https://developers.facebook.com/docs/php/howto/profilewithgraphapi/4.0.0 for an example of SDK 4 code.

SDK 4 doesn't have a root Facebook class and doesn't use $facebook = new Facebook($config); anymore.

FQL is also about to be discontinued - it's still accessible for apps created before its deprecation, but new apps must use Graph SDK 2.2 and have no ability to perform FQL queries at all.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • if include Facebook.php and base_facebook.php from sdk3 this is what says:Uncaught Exception: REST API is deprecated for versions v2.1 and higher thrown in /membri/bestparty/BPARTY4/facebook-php-sdk-master/src/base_facebook.php on line 1325 – Andrea Loda Feb 25 '15 at 16:47
  • @AndreaLoda You can't just mix/match SDK 3 and 4. Looks like your app is new enough it doesn't have access to the old v2.0 API. You'll need to do things the API 2.2 / SDK 4 way. – ceejayoz Feb 25 '15 at 16:58