PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 27, 2022

[FIXED] PHP - Get post data from Facebook page using only facebook graph

 February 27, 2022     curl, facebook, facebook-graph-api, facebook-php-sdk, php     No comments   

Issue

is there a way to get Facebook page the contents of an post using simple php.

i need to do that without The Php-sdk or the Facebook API only using the Facebook Graph and Facebook app


Solution

I have found the solution

<?php
error_reporting(0);
/*xxxxclient_idxxx='your clientid'*/
/*xxxxxxclient_secretxxxx='your client_secret'*/
//Replace "YOUR-PAGE-NAME" with your page name.
$access_str = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=xxxxclient_idxxx&client_secret=xxxxxxclient_secretxxxx&grant_type=client_credentials');
$tokenarr = str_replace('"','',$access_str);
$tokenarray = explode(":",str_replace(',',':', $tokenarr));
var_dump($tokenarray);  //Request the public posts. 
$json_str = file_get_contents('https://graph.facebook.com/YOUR-PAGE-NAME/feed??fields=attachments&fields=attachments&access_token='.$tokenarray[1]);

//decode json string into array

$data = json_decode($json_str);

foreach ($data as $posts) {
    foreach($posts as $post){
    $postit = (array) json_decode(json_encode($post), True);
    foreach ($postit as $getit) {
    echo '<p>' .$getit['data'][0]['description'].'</p>';
    echo '<img src="'.$getit['data'][0]['media']['image']['src'].'" />';
    echo "</br>-----------</br>";
        }

    }
}

?>

This script get the status text and images



Answered By - M0ns1f
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing