コード例 #1
0
ファイル: FacebookUtils.php プロジェクト: akitech/hooks-src
 public function getFeed()
 {
     // Allocate a new cURL handle
     $ch = curl_init("https://graph.facebook.com/me/feed?access_token=" . Cookie::getItem("fb_token"));
     if (!$ch) {
         die("Cannot allocate a new PHP-CURL handle");
     }
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
     $data = curl_exec($ch);
     curl_close($ch);
     $data = json_decode($data);
     $posts = [];
     foreach ($data->data as $feed) {
         $post = new \stdClass();
         $feed = (array) $feed;
         if (isset($feed["message"])) {
             $post->title = $feed["message"];
         }
         if (isset($feed["story"])) {
             $post->title = $feed["story"];
         }
         $post->time = new \DateTime($feed["created_time"]);
         $post->via = "Facebook";
         $posts[] = $post;
     }
     return $posts;
 }
コード例 #2
0
ファイル: FacebookAuth.php プロジェクト: akitech/hooks-src
 public static function collectResponse()
 {
     self::init();
     $fb = self::$fbInstance;
     $helper = $fb->getRedirectLoginHelper();
     try {
         $accessToken = $helper->getAccessToken();
     } catch (FacebookResponseException $e) {
         echo 'Graph returned an error: ' . $e->getMessage();
         exit;
     } catch (FacebookSDKException $e) {
         echo 'Facebook SDK returned an error: ' . $e->getMessage();
         exit;
     }
     if (isset($accessToken)) {
         $oAuth2Client = $fb->getOAuth2Client();
         $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
         Cookie::setItem("fb_token", $longLivedAccessToken);
         self::redirectToRedirectURL();
     }
 }