How to implement the SimplePie force_feed function in WordPress - php

When I try to parse a specific RSS feed using the native RSS widget for WordPress I receive the following error:
RSS Error: A feed could not be found at
http://trustbox.trustpilot.com/r/harringtonbrooks.co.uk.xml. A feed
with an invalid mime type may fall victim to this error, or SimplePie
was unable to auto-discover it.. Use force_feed() if you are certain
this URL is a real feed.
I have validated the feed using the http://validator.w3.org/feed/ and it states that the feed is valid. I belive that the mime type is also correct for the feed - type="application/rss+xml"
After consulting the SimplePie documentation this code is suggested as the fix - however I am clueless as to where this code would actually be implemeted within the WordPress installation.
$feed = new SimplePie();
$feed->set_feed_url('MY FEED URL');
$feed->force_feed(true);
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();
Alternatively are there any other suggestions for getting this RSS feed to actually be parsed by the reader?

Related

how to validate RSS feed URL in simplpie library

I want to validate RSS feed URL before its process for parsing. I am using willvincent/feeds library for this.
$feed = Feeds::make($rssurl);
$items = $feed->get_items();
I am parsing RSS feed like above.
So how can validate the RSS feed URL before parsing using willvincent/feeds library.
'willvincent/feeds' is just a service provider for Laravel.
You should refer to SimplePie documentation, and use the error() method to check if url throws errors. This method holds the error description.
$feed = Feeds::make('http://some-bogus-feed-url');
if($feed->error()){
//handle the feed error
}

Facebook fanpage Rss encoding error

This is my fanpage: https://www.facebook.com/kidsvideo.us
And here is my rss url: https://www.facebook.com/feeds/page.php?format=atom10&id=1433882270183943
There is error encoding when use this rss, I use php simplepie and tried feedburner with the same error: feeds.feedburner.com/KidsVideosFacebookWall
Any solution?
The solution is: Facebook use html entity in the xml. Simple use html_entity_decode() to decode the "error content".

Rss feed with PHP

Hi can Anyone tell me how to process this rss feed in php
http://www.ft.com/rss/companies/travel-leisure
when i am executing the below lines
$rss = new DOMDocument();
$rss->load('http://www.ft.com/rss/companies/travel-leisure');
it is giving an error
A PHP Error was encountered
Severity: Warning
Message: DOMDocument::load(): Opening and ending tag mismatch: link line 8 and head in http://www.ft.com/rss/companies/travel-leisure, line: 11
Thanks
If you request http://www.ft.com/rss/companies/travel-leisure without a User-Agent HTTP request header, you can get an error message back (under a 200 OK status).
This is a bug in FT's website.
As a work around, I suggest using cURL to fetch the data, and then feed a string into DOMDocument.
Why not use a dedicated library like SimplePie to process your RSS feed ?
$feed = new SimplePie('http://www.ft.com/rss/companies/travel-leisure');
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item) {
$permalink = $item->get_permalink();
$title = $item->get_title();
// Do what you want...
}
I have not tested this code, it's just to show you an example of use. Here the documentation and an example for more explanations.

check youtube video is embeddable <yt:noembed> via xml

I have following link http://gdata.youtube.com/feeds/api/videos/tYMYv1zsAxE and it return an xml file in which is located noembed tag in case the video is not embeddable.
i want to create a loop on list of videos to check which is embeddable and which is not.
Based on your clarification, it sounds like you're asking a question about parsing XML. Here's an alternative: get back JSON, and parse that. You can make a request like
http://gdata.youtube.com/feeds/api/videos/tYMYv1zsAxE?v=2&alt=jsonc&prettyprint=true
and then look at the data->accessControl->embed element within the JSON response.
Or, you know, just parse and access the YouTube API XML exactly like you'd parse the XML from any other source. There's nothing magic going on with the YouTube API XML.
$vidID = "tYMYv1zsAxE";
$url="http://gdata.youtube.com/feeds/api/videos/$vidID?v=2&alt=jsonc&prettyprint=true";
$json = file_get_contents($url, true);
$json_output = json_decode($json);
echo $json_output->data->accessControl->embed;
Simple way to check if youtube video is embeddable.
Thanks to #Jeff Posnick

Magpie RSS / User Authorization

How can I get Magpie RSS to identify itself as a user?
HTTP Response: HTTP/1.1 401 Unauthorized
is the error that i'm getting returned
Since you didn't post any code, I assume you're calling MagpieRSS like:
$rss = fetch_rss('http://www.site.com/feed.rss');
To identify as user/password, just change the URL to this format:
$rss = fetch_rss('http://username:password#www.site.com/feed.rss');
See PHP's parse_url for more info.

Categories