Created
December 2, 2015 13:50
-
-
Save korrio/b634f5ae9d80f5938313 to your computer and use it in GitHub Desktop.
Facebook Fetch (Page's post)
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 | |
| header('Content-Type: application/json'); | |
| $json = fetch(); | |
| //print_r($json["data"]); | |
| $a = array(); | |
| /* | |
| "id": 2510, | |
| "author": "Adam Kool", | |
| "image_src": "https://ununsplash.imgix.net/photo-1426604966848-d7adac402bff", | |
| "color": "#5F5B52", | |
| "date": "2015-03-17 20:00:04", | |
| "modified_date": "2015-03-17 11:09:29", | |
| "width": 2508, | |
| "height": 1672, | |
| "ratio": 1.5, | |
| "featured": 0, | |
| "category": 4, | |
| "corrupt": 0 | |
| */ | |
| $i = 0; | |
| foreach ($json["data"] as $k => $v) { | |
| $name = $v["name"]; | |
| $a1 = array(); | |
| if(strlen($name) <= 30) { | |
| $a1['id'] = intval($v["id"]); | |
| //$a1['name'] = $v["name"]; | |
| $a1['author'] = $v["message"]; | |
| $a1['image_src'] = "https://graph.facebook.com/".$v["object_id"]."/picture/?type=normal"; | |
| $a1['color'] = "#5F5B52"; | |
| $a1['date'] = "2015-03-17 11:09:29"; | |
| $a1['modified_date'] = "2015-03-17 11:09:29"; | |
| $a1['width'] = 800; | |
| $a1['height'] = 600; | |
| $a1['ratio'] = 1; | |
| $a1['featured'] = 0; | |
| $a1['category'] = 4; | |
| $a1['corrupt'] = 0; | |
| $i++; | |
| $a[] = $a1; | |
| } | |
| # code... | |
| } | |
| $res = array('offset'=>0,'count'=>count($json["data"]),'total'=>count($json["data"]),'data' => $a); | |
| $rjson = json_encode($res); | |
| echo $rjson; | |
| function fetch() { | |
| $graph_url = "https://graph.facebook.com/v2.4/190008514462582/posts?fields=id,from,name,message,created_time,story,description,link,picture,object_id&limit=50&access_token=150849908413827|a20e87978f1ac491a0c4a721c961b68c"; | |
| //$graph_url= "http://graph.facebook.com/agirllikeyou061/photos/uploaded?fields=name,images,source,from&limit=100"; | |
| $postData = "url=" . urlencode($photo_url) | |
| . "&message=" . urlencode('') | |
| . "&access_token=" .$access_token; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $graph_url); | |
| curl_setopt($ch, CURLOPT_HEADER, 0); | |
| //curl_setopt($ch, CURLOPT_POST, 1); | |
| //curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); | |
| $output = curl_exec($ch); | |
| //print $output; | |
| $json = json_decode($output,1); | |
| curl_close($ch); | |
| return $json; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment