Last active
September 29, 2017 09:45
-
-
Save bluvertigo/cec0276789d2baa35913 to your computer and use it in GitHub Desktop.
Facebook Connect graph api - Acces Token -> http://goo.gl/TGkg55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| session_start(); | |
| // added in v4.0.0 | |
| require_once 'facebook-php-sdk/autoload.php'; | |
| use Facebook\FacebookSession; | |
| use Facebook\FacebookRedirectLoginHelper; | |
| use Facebook\FacebookRequest; | |
| use Facebook\FacebookResponse; | |
| use Facebook\FacebookSDKException; | |
| use Facebook\FacebookRequestException; | |
| use Facebook\FacebookAuthorizationException; | |
| use Facebook\GraphObject; | |
| use Facebook\Entities\AccessToken; | |
| use Facebook\HttpClients\FacebookCurlHttpClient; | |
| use Facebook\HttpClients\FacebookHttpable; | |
| // start session | |
| // init app with app id and secret | |
| FacebookSession::setDefaultApplication( 'xxxx', 'xxx' ); | |
| //ACCESS TOKEN generato tramite questo link | |
| //https://developers.facebook.com/tools/explorer?method=GET&path=115347425227341%2Fposts&version=v2.2& | |
| // con btn GET APP TOKEN | |
| $session = new FacebookSession('xxx|xxx'); | |
| // To validate the session: | |
| try { | |
| $session->validate(); } | |
| catch (FacebookRequestException $ex) { | |
| // Session not valid, Graph API returned an exception with the reason. | |
| echo $ex->getMessage(); | |
| } | |
| catch (\Exception $ex) { | |
| // Graph API returned info, but it may mismatch the current app or have expired. | |
| echo $ex->getMessage(); | |
| } | |
| function get_image_from_obj_id($session,$obj_id){ | |
| $request_inner = new FacebookRequest( | |
| $session, | |
| 'GET', | |
| '/'.$obj_id.'?fields=images' | |
| ); | |
| $response_inner = $request_inner->execute(); | |
| $graphObject = $response_inner->getGraphObject(); | |
| $graphObject = $graphObject->getProperty('images'); | |
| $images_fb = $graphObject->asArray(); | |
| foreach ($images_fb as $key => $images_fb_single) { | |
| if($images_fb_single->height>500){ | |
| return $images_fb_single->source; | |
| break; | |
| } | |
| } | |
| } | |
| $request = new FacebookRequest( | |
| $session, | |
| 'GET', | |
| '/115347425227341/posts' | |
| ); | |
| $response = $request->execute(); | |
| $graphObject_post = $response->getGraphObject(); | |
| $graphObject_post = $graphObject_post->getProperty('data'); | |
| $posts_fb = $graphObject_post->asArray(); | |
| foreach ($posts_fb as $key => $posts_fb_single) { | |
| if($posts_fb_single->type==="status" || $posts_fb_single->type==="photo"){ | |
| if($posts_fb_single->message){ | |
| echo '<li class="item">'; | |
| echo ' <h3>'.$posts_fb_single->from->name.'</h3>'; | |
| //echo ' <h5>'.$myTime.'</h5>'; | |
| if($posts_fb_single->object_id){ | |
| echo ' <img src="'.get_image_from_obj_id($session,$posts_fb_single->object_id).'" width="100%"/>'; | |
| } | |
| echo ' <p>'.$posts_fb_single->message.'</p>'; | |
| //$fb_feature_img = str_replace('v/t1.0-9/s130x130/', '', $single_post['content']); | |
| //$fb_remove_link = str_replace('href', 'link_esterno', $fb_feature_img); | |
| //echo ' <a href="'.$single_post['alternate'].'" target="_blank"><p>'.$fb_remove_link.'</p></a>'; | |
| echo '</li>'; | |
| } | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment