示例#1
0
<?php

session_start();
require_once __DIR__ . '/facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.php';
require_once __DIR__ . '/facebook-php-sdk-v4-5.0.0/src/Facebook/Facebook.php';
$fb = new Facebook\Facebook(['app_id' => '1023466864382694', 'app_secret' => '814079f172a9399b12177a08a9cbbc42', 'default_graph_version' => 'v2.4']);
$token = 'CAAOi1nLkEuYBAAb450P075eXAo7scVnZAl1GXPwffgIbJqfO0AZC54bZA7T4ehfLdo574gdBiC1Wfw1CwZBdviCrLNywe2MDlK3cXdu5XqCWmtFn2s5LmGuZAsJeC5rLvZB2O4arqDdnEf6sIn98vu4lnwZA4qhypQnIbRI05Y0vvBGg9w3zj9jdVadMdzMIh13f0xtZCnEyNAZDZD';
$fb->setDefaultAccessToken($token);
$requestFriends = $fb->get('/me/taggable_friends?fields=name&limit=100');
$friends = $requestFriends->getGraphEdge();
if ($fb->next($friends)) {
    $allFriends = array();
    $friendsArray = $friends->asArray();
    $allFriends = array_merge($friendsArray, $allFriends);
    while ($friends = $fb->next($friends)) {
        $friendsArray = $friends->asArray();
        $allFriends = array_merge($friendsArray, $allFriends);
    }
    foreach ($allFriends as $key) {
        echo $key['name'] . "<br>";
    }
    echo count($allfriends);
} else {
    $allFriends = $friends->asArray();
    $totalFriends = count($allFriends);
    foreach ($allFriends as $key) {
        echo $key['name'] . "<br>";
    }
}
    }
    // getting all posts published by user
    try {
        $posts_request = $fb->get('/me/posts?limit=500');
    } catch (Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
    $total_posts = array();
    $posts_response = $posts_request->getGraphEdge();
    if ($fb->next($posts_response)) {
        $response_array = $posts_response->asArray();
        $total_posts = array_merge($total_posts, $response_array);
        while ($posts_response = $fb->next($posts_response)) {
            $response_array = $posts_response->asArray();
            $total_posts = array_merge($total_posts, $response_array);
        }
        print_r($total_posts);
    } else {
        $posts_response = $posts_request->getGraphEdge()->asArray();
        print_r($posts_response);
    }
    // Now you can redirect to another page and use the access token from $_SESSION['facebook_access_token']
} else {
    $helper = $fb->getRedirectLoginHelper();
    $loginUrl = $helper->getLoginUrl('https://apps.facebook.com/APP_NAMESPACE/', $permissions);
示例#3
0
require_once __DIR__ . '/vendor/autoload.php';
$assetsFolder = __DIR__ . '/downloaded-assets';
$nodes = array();
$fb = new Facebook\Facebook(['app_id' => '1671486879750098', 'app_secret' => '34571d3ffa4960308192d362dc4d0711', 'default_graph_version' => 'v2.4']);
$fb->setDefaultAccessToken('1671486879750098|34571d3ffa4960308192d362dc4d0711');
$request = $fb->request('GET', '/1410974149199136/posts', ['fields' => 'full_picture,link,source,properties,type,created_time,updated_time,to,message,message_tags,story,story_tags', 'limit' => 100]);
try {
    $response = $fb->getClient()->sendRequest($request);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}
$edge = $response->getGraphEdge();
do {
    foreach ($edge as $post) {
        $nodes[$post->getField('id')] = $post->asArray();
    }
} while ($edge = $fb->next($edge));
if (!empty($nodes)) {
    $filename = 'data-' . time() . '.json';
    file_put_contents($assetsFolder . "/{$filename}", json_encode($nodes));
    print "Saved " . count($nodes) . " nodes to {$filename}\n";
} else {
    echo "Something went wrong!\n";
}
 }
 // get list of pages liked by user
 try {
     $requestLikes = $fb->get('/me/likes?limit=100');
     $likes = $requestLikes->getGraphEdge();
 } catch (Facebook\Exceptions\FacebookResponseException $e) {
     // When Graph returns an error
     echo 'Graph returned an error: ' . $e->getMessage();
     exit;
 } catch (Facebook\Exceptions\FacebookSDKException $e) {
     // When validation fails or other local issues
     echo 'Facebook SDK returned an error: ' . $e->getMessage();
     exit;
 }
 $totalLikes = array();
 if ($fb->next($likes)) {
     $likesArray = $likes->asArray();
     $totalLikes = array_merge($totalLikes, $likesArray);
     while ($likes = $fb->next($likes)) {
         $likesArray = $likes->asArray();
         $totalLikes = array_merge($totalLikes, $likesArray);
     }
 } else {
     $likesArray = $likes->asArray();
     $totalLikes = array_merge($totalLikes, $likesArray);
 }
 // printing data on screen
 foreach ($totalLikes as $key) {
     echo $key['name'] . '<br>';
 }
 // Now you can redirect to another page and use the access token from $_SESSION['facebook_access_token']
示例#5
0
<?php

session_start();
require_once __DIR__ . '/facebook/src/Facebook/autoload.php';
$fb = new Facebook\Facebook(['app_id' => '135572810141672', 'app_secret' => '4780932d14d2d74135964d8ab1afb0bc', 'default_graph_version' => 'v2.5']);
try {
    // Requires the "read_stream" permission
    $response = $fb->get('/me/feed?fields=id,photos&amp;limit=5', $_SESSION['facebook_access_token']);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}
// Page 1
$feedEdge = $response->getGraphEdge();
var_dump($feedEdge);
foreach ($feedEdge as $status) {
    var_dump($status->asArray());
}
// Page 2 (next 5 results)
$nextFeed = $fb->next($feedEdge);
if ($nextFeed) {
    foreach ($nextFeed as $status) {
        var_dump($status->asArray());
    }
}
 }
 // getting all photos of user
 try {
     $photos_request = $fb->get('/me/photos?limit=100&type=uploaded');
     $photos = $photos_request->getGraphEdge();
 } catch (Facebook\Exceptions\FacebookResponseException $e) {
     // When Graph returns an error
     echo 'Graph returned an error: ' . $e->getMessage();
     exit;
 } catch (Facebook\Exceptions\FacebookSDKException $e) {
     // When validation fails or other local issues
     echo 'Facebook SDK returned an error: ' . $e->getMessage();
     exit;
 }
 $all_photos = array();
 if ($fb->next($photos)) {
     $photos_array = $photos->asArray();
     $all_photos = array_merge($photos_array, $all_photos);
     while ($photos = $fb->next($photos)) {
         $photos_array = $photos->asArray();
         $all_photos = array_merge($photos_array, $all_photos);
     }
 } else {
     $photos_array = $photos->asArray();
     $all_photos = array_merge($photos_array, $all_photos);
 }
 foreach ($all_photos as $key) {
     $photo_request = $fb->get('/' . $key['id'] . '?fields=images');
     $photo = $photo_request->getGraphNode()->asArray();
     echo '<img src="' . $photo['images'][2]['source'] . '"><br>';
 }