<?php session_start(); header(‘Content-type:text/html; charset=UTF-8‘); require_once ‘./facebook-php-sdk-v4-4.0-dev/autoload.php‘; use Facebook\FacebookRequest; use Facebook\GraphUser; use Facebook\FacebookRequestException; use Facebook\FacebookSession; use Facebook\FacebookRedirectLoginHelper; FacebookSession::setDefaultApplication(‘470947919708420‘, ‘86b6acdec0ffcee0d40f8fcf8e6df2e2‘); // 回调获取session $helper = new FacebookRedirectLoginHelper(‘http://www.adtuu-server.com/facebook/callback.php‘); try { $session = $helper->getSessionFromRedirect(); } catch(FacebookRequestException $ex) { // When Facebook returns an error echo ‘1:‘; var_dump($ex->getMessage()); } catch(\Exception $ex) { // When validation fails or other local issues echo ‘2:‘; var_dump($ex->getMessage()); } if ($session) { // Logged in 这个token返回的 有效期节点没有值 echo $access_token = $session->getToken(); var_dump($session); /* ここで有効期限を延長させてます 60天token有效期*/ $longSession = $session->getLongLivedSession(); $accessToken = $longSession->getToken(); echo ‘<br />‘ . $accessToken; var_dump($longSession); } exit; //https://developers.facebook.com/docs/graph-api/reference/v2.1/user //$access_token = ‘CAAGsUxt2QQQBAHiUPx01qRrjaFnZAZCFUpv8bvD3mDTWvNBXnlY7MYrRNk3VBTCKOhhnZA1Gj4dq8PhRsXZCtFQz66ivM3wqSmiSi7jP8ZBg1CPLvKxeJKUWszWV0cfZAoaHMk8CfqA6mjGXC5G1ZBfWCC7IQimExlujpWs1CwayjiAuqtPrZBQBevuyZB9ySEfZAUjMTC6SJsQD1pTp9MEaf8‘; $access_token = ‘CAAGsUxt2QQQBALzjzpzP0gINsla10L4ZClsP5KhbCmsO0gf6VUSNPJYJHy7cOiYhwxqYZA0fDALEINcZBZBqGlKHZBXSdygYNUHCQskZC6DfkPmH0ivS6bqdTbdGwViFkiDHZCMw3evAWQ3BNINvMAgVaaWL1xvi2wqEVu70p90hIkt3xVgbbHnAnrfgPA7iCV7z5TXZCx5SKboWvd80JHdq‘; $session = new FacebookSession($access_token); try { $user_profile = (new FacebookRequest( $session, ‘GET‘, ‘/me‘ ))->execute()->getGraphObject(GraphUser::className()); echo "Name: " . $user_profile->getName(); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode(); echo " with message: " . $e->getMessage(); } try { $friends = (new FacebookRequest( $session, ‘GET‘, ‘/me/friendlists‘ ))->execute()->getGraphObject(GraphUser::className()); var_dump($friends); } catch (Exception $e) { var_dump($e); } exit; try { $response = (new FacebookRequest( $session, ‘POST‘, ‘/me/feed‘, array( ‘link‘ => ‘http://www.adtuu.com‘, ‘message‘ => ‘Hi, Adtuu !!!‘ ) ))->execute()->getGraphObject(); echo "Posted with id: " . $response->getProperty(‘id‘); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode(); echo " with message: " . $e->getMessage(); } try { // Upload to a user‘s profile. The photo will be in the // first album in the profile. You can also upload to // a specific album by using /ALBUM_ID as the path $response = (new FacebookRequest( $session, ‘POST‘, ‘/me/photos‘, array( ‘source‘ => new CURLFile(‘/Users/zhoutingze/webroot/facebook/post.jpg‘, ‘image/jpeg‘), ‘message‘ => ‘User provided message‘ ) ))->execute()->getGraphObject(); // If you‘re not using PHP 5.5 or later, change the file reference to: // ‘source‘ => ‘@/path/to/file.name‘ echo "Posted with id: " . $response->getProperty(‘id‘); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode(); echo " with message: " . $e->getMessage(); } try { $response = (new FacebookRequest( $session, ‘POST‘, ‘/me/feed‘, array( ‘link‘ => ‘http://www.baidu.com/img/bd_logo1.png‘, ‘message‘ => ‘Hi, Adtuu !!!‘ ) ))->execute()->getGraphObject(); echo "Posted with id: " . $response->getProperty(‘id‘); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode(); echo " with message: " . $e->getMessage(); }
时间: 2024-11-06 12:47:47