Page 1 of 1

Facebook RSS won't return all posts from request...

Posted: Mon Jan 27, 2014 4:44 pm
by phper2014
UPDATE:
I have found that the problem is something about the server configuration, but I'm not sure what it is and am looking for a work around to the issue. I have two identical scripts running on two different hosting providers and one works correctly. I will give you both addresses so you can make comparisons and I hope you will see the issue I am missing that is causing this problem. You will notice what is wrong easily, the working script has 4 times as many posts data.

First the script with the issue:
uploaded to http://byethost.com/ a free hosting account, scripts need to work with these providers if possible.

http://webpresscreative.byethost24.com/test5.php

The working script uploaded to Godaddy a premium business account.

http://softnetwd.com/test5.php

The script is this one below:

I have an issue with this script, it works but there is a huge difference in the xml data from Facebook from loading a browser and looking at the xml doc and what the script gets from Facebook. When the script runs Facebook returns much less data but the xml doc is complete so its not timing out or any other error, just a lot less posts.

Got any ideas, header info missing or something? I can't think of what it may be, hope somebody else can...

Here is the script:

Code: Select all

<?php
//ini_set('display_errors', 'off'); 

function remote_file_size($url){
$data = get_headers($url, true);
if (isset($data['Content-Length']))
return (int) $data['Content-Length'];
}

$rss_date=date('Y-m-d\TH:i:sP');
$fb_page_id='626664130730204'; 
$rss_feed_url='http://www.facebook.com/feeds/page.php?format=atom10&id='.$fb_page_id;
$pg_name='facebook test page';
$pg_name=urlencode($pg_name);

$filesize=remote_file_size($rss_feed_url);

if($filesize > 0) {
ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
$xml = simplexml_load_file($rss_feed_url,NULL,LIBXML_NOCDATA);

$feed_info['id']=urlencode((string)$xml->id);
$feed_info['title']=urlencode((string)$xml->title);

foreach($xml->link as $var){
$links[$cnt]=urlencode((string)$var[href]);
$cnt++;}
$feed_info['link']=implode('|', $links);

$feed_info['updated']=urlencode((string)$xml->updated);
$feed_info['icon']=urlencode((string)$xml->icon);
$feed_info['logo']=urlencode((string)$xml->logo);

$cnt=0;
foreach($xml->entry as $entry_var) {
if(strlen((string)$entry_var->id) == 0){$id_ans='0';}else{
$id_ans=urlencode((string)$entry_var->id);}
$entry_data['id']=$entry_data['id'].$id_ans.'|';
$fb_wall['id'.$cnt]=$id_ans;
$entry_data['link']=$entry_data['link'].urlencode((string)$entry_var->link[href]).'|';
$fb_wall['link'.$cnt]=urlencode((string)$entry_var->link[href]);
$entry_data['title']=$entry_data['title'].urlencode((string)$entry_var->title).'|';
$fb_wall['title'.$cnt]=urlencode((string)$entry_var->title);
$entry_data['published']=$entry_data['published'].urlencode((string)$entry_var->published).'|';
$fb_wall['published'.$cnt]=urlencode((string)$entry_var->published);
$entry_data['updated']=$entry_data['updated'].urlencode((string)$entry_var->updated).'|';
$fb_wall['updated'.$cnt]=urlencode((string)$entry_var->updated);
$entry_data['name']=$entry_data['name'].urlencode((string)$entry_var->author->name).'|';
$fb_wall['name'.$cnt]=urlencode((string)$entry_var->author->name);
$entry_data['content']=$entry_data['content'].urlencode((string)$entry_var->content).'|';
$fb_wall['content'.$cnt]=urlencode((string)$entry_var->content);

//echo var_dump((string)$entry_var->content);

$cnt++;}
}

if($feed_info && $entry_data){

// removed db code

$cnt=0;
while(strlen($fb_wall['id'.$cnt]) > 0) {

$id=$fb_wall['id'.$cnt];
$link=$fb_wall['link'.$cnt];
$title=$fb_wall['title'.$cnt];
$published=$fb_wall['published'.$cnt];
$updated=$fb_wall['updated'.$cnt];
$name=$fb_wall['name'.$cnt];
$content=$fb_wall['content'.$cnt];

// removed db code

$cnt++;
}

}else{$rss_db='error';}

// below added to view result for testing:

$temps=explode('|', $entry_data['content']);$cnt=0;
foreach($temps as $var){echo '<hr>'.urldecode($var).'<hr>';}

//print_r($xml);
?>
You can omit the database code areas and I have added

Code: Select all

$temps=explode('|', $entry_data['content']);$cnt=0;
foreach($temps as $var){echo '<hr>'.urldecode($var).'<hr>';}
in the last line to view results for testing...

Thanks!!

Re: Facebook RSS feed simplexml_load_file need help...

Posted: Mon Jan 27, 2014 5:10 pm
by Celauran
Something's up with Facebook. I can load the feed fine in my browser but SimpleXMLElement says it's not valid XML and throws an exception. Found this, which seems to do the trick: https://gist.github.com/banago/3864515

Re: Facebook RSS feed simplexml_load_file need help...

Posted: Mon Jan 27, 2014 6:20 pm
by phper2014
I have noticed that the feed does not validate, but I did try the script you suggested. It does exactly the same thing mine does. There are about 8 posts listed from the scripts but there are more than 15 posts on the FB page and in the RSS feed when you view it in Chrome. IE won't work because the feed from FB won't validate but that is not the issue ether, I viewed the RSS feed as an XML doc by using fread() and its the same XML doc in all cases and intact but with a fraction of the posts as if FB knows its a script requesting the feed and only gives a fraction of the posts as a result... maybe it needs to know how many posts to return along with the page id, and format is there another value that needs to be included in the feed request as to how many posts to return in the RSS data?

another script that was suggested by a user that returns the same result as my script: https://gist.github.com/banago/3864515

Code: Select all

<?php
 
/**
 * Facebook Page Feed Parser 
 * 
 * @using SimpleXML
 */
function fb_parse_feed( $page_id, $no) {
	
    // You need to query the feed as a browser.
    ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
 
    // URL to the Facebook page's RSS feed.
    $rss_url = 'http://www.facebook.com/feeds/page.php?id=' . $page_id . '&format=rss20';
    $xml = simplexml_load_file( $rss_url );
  
    $out = ''; 
    $i = 1;
    foreach( $xml->channel->item as $item ){
 
        $out .= '<div class="entry">';
        $out .= '<h3 class="title"><a href="' . $item->link . '">' . $item->title . '</a></h3>';
        $out .= '<div class="meta">' . $item->pubDate . ' by '. $item->author .'</div>';
        $out .= '<div class="content">' . $item->description . '</div></div>';
        
		if( $i == $no ) break;
		$i++;
	}
    
    echo $out;
	return $xml;
}

$page_id=626664130730204;
$no=100;
print_r(fb_parse_feed( $page_id, $no));
?>

Re: Facebook RSS feed simplexml_load_file need help...

Posted: Mon Jan 27, 2014 7:07 pm
by Celauran
phper2014 wrote:I have noticed that the feed does not validate, but I did try the script you suggested. It does exactly the same thing mine does. There are about 8 posts listed from the scripts but there are more than 15 posts on the FB page and in the RSS feed when you view it in Chrome.
Really? I get 28.

Code: Select all

<?php

$rss_url = 'http://www.facebook.com/feeds/page.php?format=atom10&id=626664130730204';

$curl = curl_init();

// You need to query the feed as a browser.
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.

curl_setopt($curl, CURLOPT_URL, $rss_url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_REFERER, '');
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);

$raw_xml = curl_exec($curl); // execute the curl command
curl_close($curl); // close the connection

$xml = new SimpleXMLElement($raw_xml, LIBXML_NOCDATA);
echo count($xml->entry);

Re: Facebook RSS won't return all posts from request...

Posted: Mon Jan 27, 2014 8:42 pm
by phper2014
I just tried this script and the result is 8, this is very puzzling ... your result was 28? Please try again with this script, I can't understand how the results could be different when using the exact same scripts unless the server is somehow involved. My server does block get_file_contents() but I am not aware it is configured to change the results using these functions.

Here is the result I get from your script after adding print_r($xml); to the last line to view the result details. When you run my script (the first script from the first post) do you get the same result as well 28?


[text]SimpleXMLElement Object
(
[id] => 0f80cf1ad2c4cbd6d9fe47ae4ab3ee11
[generator] => Facebook Syndication
[title] => Web Press Creative GUI CMS Website Free Download's Facebook Wall
[link] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[href] => http://www.facebook.com/
)

)

[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => self
[href] => http://www.facebook.com/feeds/page.php? ... 4130730204
)

)

)

[updated] => 2014-01-26T18:36:17-08:00
[icon] => http://www.facebook.com/favicon.ico
[logo] => http://profile.ak.fbcdn.net/hprofile-ak ... 2597_n.jpg
[entry] => Array
(
[0] => SimpleXMLElement Object
(
[title] => Development has begun on a template/plug-in set that will allow Web Press Creati...
[id] => 6d6913f2557bc1ef29fad1c92c78af3d
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/photo.php?fbid= ... 204&type=1
)

)

[published] => 2014-01-27T02:36:17+00:00
[updated] => 2014-01-27T02:36:17+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => Development has begun on a template/plug-in set that will allow Web Press Creative users to build their own personal social website that is linked with Facebook and allows for bi-directional posting with any Facebook account displaying the Facebook page content, sorting, storage and editing along with many other types of data manipulation and usages with additional options of functionality that Facebook does not offer with the Facebook page alone.<br /> <br /> Along with all the features of Facebook users can "Tune in" to the myFBpage channel to interact with and endless possibility of features like videos, news, games or any media channel masters wish to provide. Applications will become available the control channel masters accounts as another plug-in for Web Press Creative.<br /> <br /> Requests for functions, services and features is very important to our developers at this stage of the development so if there is anything you have always wanted Facebook could do or have any great ideas you want to share now is the time to tell us. We can make it happen! Let us know what you would like!!<br /> <br /> More information on the progress on this project will be available as it is available.<br /> <br /> Thank you,<br /> Donald Dion Web Press Creative web application developer.<br/><br/><a href="http://www.facebook.com/photo.php?fbid= ... nt_count=1" id="" title="" target="" onclick="" style=""><img class="img" src="http://photos-g.ak.fbcdn.net/hphotos-ak ... 3300_s.png" alt="" /></a>
)

[1] => SimpleXMLElement Object
(
[title] => SimpleXMLElement Object
(
[0] =>
)

[id] => 1bdb6059ceb757696b5a0c9971da7707
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/webpresscreativ ... 6840533568
)

)

[published] => 2014-01-23T20:18:29+00:00
[updated] => 2014-01-23T20:18:29+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => <a href="http://profile.ak.fbcdn.net/hprofile-ak ... 2597_s.jpg" id="" title="" target="" onclick="" style="">http://profile.ak.fbcdn.net/hprofile-ak ... jpg</a><br /><br/><a href="/webpresscreativedownload/posts/642733005789983" id="" style="">Web Press Creative GUI CMS Website Free Download</a><br/>Development has begun on a template/plug-in set that will allow Web Press Creative users to build their own personal social website that is linked with Facebook and allows for bi-directional posting with any Facebook account displaying the Facebook page content, sorting, storage and editing along with many other types of data manipulation and usages with additional options of functionality that Facebook does not offer with the Facebook page alone. Requests for functions, services and features is very important to our developers at this stage of the development so if there is anything you have always wanted Facebook could do or have any great ideas you want to share now is the time to tell us. We can make it happen! Let us know what you would like!! More information on the progress on this project will be available as it is available. Thank you, Donald Dion Web Press Creative web application developer.
)

[2] => SimpleXMLElement Object
(
[title] => Development has begun on a template/plug-in set that will allow Web Press Creati...
[id] => d09636c978aab175cc7af3baa64cad2b
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/webpresscreativ ... 3005789983
)

)

[published] => 2014-01-23T20:18:03+00:00
[updated] => 2014-01-23T20:18:03+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => Development has begun on a template/plug-in set that will allow Web Press Creative users to build their own personal social website that is linked with Facebook and allows for bi-directional posting with any Facebook account displaying the Facebook page content, sorting, storage and editing along with many other types of data manipulation and usages with additional options of functionality that Facebook does not offer with the Facebook page alone.<br /> <br /> Requests for functions, services and features is very important to our developers at this stage of the development so if there is anything you have always wanted Facebook could do or have any great ideas you want to share now is the time to tell us. We can make it happen! Let us know what you would like!!<br /> <br /> More information on the progress on this project will be available as it is available.<br /> <br /> Thank you, <br /> Donald Dion Web Press Creative web application developer.
)

[3] => SimpleXMLElement Object
(
[title] => Whats in development right now?

Web Press Creative developers are beginning dev...
[id] => 6b6cefd3633945861e3de07edfe9748f
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/webpresscreativ ... 6916843592
)

)

[published] => 2014-01-02T21:04:04+00:00
[updated] => 2014-01-02T21:04:04+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => Whats in development right now?<br /> <br /> Web Press Creative developers are beginning development on the following:<br /> <br /> WPC self install plug-in – this plug-in will self install additional add-on's, template sets and other future available scripts and updates.<br /> <br /> New template theme sets are coming soon !<br /> <br /> WPC language compiler for a symbolic scripting language that loads and utilizes core functions and includes scripts with simple directives that compiles scripting from a database library containing WPC 'Web Press Creative Preprocessed Context' directives along with the PHP functions making PHP script writing for Web Press Creative quick and simple.
)

[4] => SimpleXMLElement Object
(
[title] => GUI CMS MENU DATABASE SECTION

This menu system allows the administrative user t...
[id] => 62dfbbfbb4a168874d2bce9d8bd9109e
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/webpresscreativ ... 5863510364
)

)

[published] => 2014-01-02T21:01:39+00:00
[updated] => 2014-01-02T21:01:39+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => GUI CMS MENU DATABASE SECTION<br /> <br /> This menu system allows the administrative user to enter into all aspects of the website core and make changes or edit web pages and settings.<br /> <br /> Database section:<br /> <br /> This section displays all data in the database and allows that data to be searched for specific values. These values will all be highlighted in red throughout all the data. The search can ether be case insensitive or if 'find exact values' box is checked becomes case sensitive.
)

[5] => SimpleXMLElement Object
(
[title] => GUI CMS MENU MENU TYPES SECTION

This menu system allows the administrative user...
[id] => 63239897e990b960a0159b3d5c3784ad
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/webpresscreativ ... 5753510375
)

)

[published] => 2014-01-02T21:01:24+00:00
[updated] => 2014-01-02T21:01:24+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => GUI CMS MENU MENU TYPES SECTION<br /> <br /> This menu system allows the administrative user to enter into all aspects of the website core and make changes or edit web pages and settings.<br /> <br /> Menu types:<br /> <br /> In this section all available installed menus are listed and can be launched for use, each has a description of the menu and unwanted menus installed can be completely removed by clicking 'delete'.
)

[6] => SimpleXMLElement Object
(
[title] => GUI CMS MENU PLUG-IN'S SECTION

This menu system allows the administrative user...
[id] => a98ed7233f37dc35e66048e24864a967
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/webpresscreativ ... 5653510385
)

)

[published] => 2014-01-02T21:01:06+00:00
[updated] => 2014-01-02T21:01:06+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => GUI CMS MENU PLUG-IN'S SECTION<br /> <br /> This menu system allows the administrative user to enter into all aspects of the website core and make changes or edit web pages and settings.<br /> <br /> Plug-in's section:<br /> <br /> In this section all the available plug-in's install will be listed and the user is able to change settings on plug-in's. Installed plug-in's can be uninstalled by clicking on 'delete' to remove plug-in and all files, folders and database entries associated with the unwanted plug-in.
)

[7] => SimpleXMLElement Object
(
[title] => GUI CMS MENU TEMPLATE SECTION

This menu system allows the administrative user t...
[id] => 2968bb9e54b219ea2428ee40b40e08e4
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[rel] => alternate
[type] => text/html
[href] => http://www.facebook.com/webpresscreativ ... 5500177067
)

)

[published] => 2014-01-02T21:00:45+00:00
[updated] => 2014-01-02T21:00:45+00:00
[author] => SimpleXMLElement Object
(
[name] => Web Press Creative GUI CMS Website Free Download
)

[content] => GUI CMS MENU TEMPLATE SECTION<br /> <br /> This menu system allows the administrative user to enter into all aspects of the website core and make changes or edit web pages and settings.<br /> <br /> Template selection section:<br /> <br /> Select the preferred template for the website from the drop down menu and click on 'preview' to see what the template will look like. To change the template used for the website click 'save' the website will then use the new template selection for all web pages.<br /> <br /> Menu button will display the menu for that template and once it is selected for any special settings for that template if any are available.
)

)

)[/text]

Re: Facebook RSS won't return all posts from request...

Posted: Tue Jan 28, 2014 1:24 am
by phper2014
The issue is caused by the domain. A third test ran at: http://webpresscreative.org/test5.php also works correctly, the issue is only current when a sub-domain is used to host the website. Why this causes the issue is unknown, maybe the sub-domain hosts the web page within an iframe? I don't know, any suggestions as to why?