Warning: simplexml_load_file(http://gdata.youtube.com/feeds/api/videos/b3a5BgqObEY): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
is the error that I get with the youtube feed in my site. I was told it was because a YouTube video was removed, but I don't know enough about PHP to fix this error. Can someone help push me in the right direction? When I searched for this error, all that came up was xml stuff and this is all in php so that doesn't help.
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'. $youtube->yt_videoId;
// read feed into SimpleXML object
$entry = simplexml_load_file($feedURL);
// parse video entry
$video = $main->parseVideoEntry($entry);
I'll keep looking, but thanks in advance if you have a good link for me to look at while I research this problem.
If you visit the url http://gdata.youtube.com/feeds/api/videos/b3a5BgqObEY you'll see "Private video", which is the reason you can't get the feed...
EDIT: You can use the V3 of the API to send an authentificated request; check this url to learn how to do it: https://developers.google.com/youtube/v3/
Greetings
Related
I am trying to fetch some data like first name, last name from LinkedIn. I am using the below code for the same. But I am getting NULL in response. I tried some solutions from SO and other websites but none of them worked.
Below is the code I am using:-
$url = 'http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-urls::(original),headline,public-profile-url,location,industry,positions,email-address)?format=json&outh2_access_token='.$accessToken;
$user = file_get_contents($url,false);
var_dump(json_decode($user));
die();
Below is the response that I am getting.
[16-Jul-2018 12:27:20 Europe/London] PHP Warning: file_get_contents(http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-urls::(original),headline,public-profile-url,location,industry,positions,email-address)?format=json&outh2_access_token=###########): failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized
Basically what I want is to fetch the data from LinkedIn using php, if anybody has done this before please share the solution with me.
I'm trying to develop and Instagram application but I'm struggling to get a json inserting the access token via variable.
That's my code:
$personal = json_decode(file_get_contents('https://api.instagram.com/v1/users/self/?access_token={$accesstoken}'));
And the error that I receive is this:
PHP Warning: file_get_contents(https://api.instagram.com/v1/users/self/?access_token={$accesstoken}): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
I already tried to see if I get the variable $accesstoken from the previous form and it's all right, because if I echo-it on the page it pops up.
I tried the function preg_replace to understand if the problem were the white spaces, but nothing.
I don't want to use cURL if it is not mandatory.
What's wrong with the code (and me)?
Thanks in advance!
Edit:
As I answered to #FirstOne: yes, I already tried to put the variable (access token) manually and in this way it works.
I'm trying to do a composite search in bing search API using php. From this documentation i got this.
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&Query=%27XBox%27&$top=1 This gives some result which i don't know to parse and show the result. I tried `simplexml_load_file()` to parse but no use.
If i mention json format request like below i get a bad request sent error( failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request) and file_get_contents() error
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&?$format=json&Query=%27XBox%27&$top=1
How to get the result with json?
Correct query for you is: (I removed "?" before $format=json)
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&$format=json&Query=%27XBox%27&$top=1
I've been using the following code to scrape keywords from Google:
$data=file_get_contents('http://clients1.google.com/complete/search?hl=en&gl=us&q='.$keyword);
However, my script has suggest started showing these errors:
Warning: file_get_contents(http://clients1.google.com/complete/search?hl=en&gl=us&q=money) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/username/public_html/keywords.php on line 10
I'm guessing this is being caused by Google changing the link? Does anyone know what the new link would be or what I need to change in my code?
Try this:
$url = 'http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q=';
$data=file_get_contents($url . urlencode( $keyword ) );
Hope it helps.
I've got a page on a website that's pulling my favorites feed from YouTube and embedding them into site.
The problem is it's working 80% of the time, but the other 20% of the time i'm getting errors on the page - nothing in the code is changing to cause this, so i'm wondering what might be causing this, or if there's a better way to do what i'm doing...
The Error I'm gettings is a 403 Forbidden when retrieving the XML feed... here's what it looks like (note: the line numbers won't match exactly, because i've simplified the code sample below.
The XML feed in question is here:
https://gdata.youtube.com/feeds/api/users/umarchives/favorites
Warning: simplexml_load_file(https://gdata.youtube.com/feeds/api/users/umarchives/favorites) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /mnt/stor3-wc2-dfw1/web/content/videos.php on line 42
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "https://gdata.youtube.com/feeds/api/users/umarchives/favorites" in /mnt/stor3-wc2-dfw1/web/content/videos.php on line 42
Warning: Invalid argument supplied for foreach() in /mnt/stor3-wc2-dfw1/web/content/videos.php on line 47
Here's the code i'm using:
<?php
// set feed URL
$YouTubeUsername = "umarchives";
$feedURL = "https://gdata.youtube.com/feeds/api/users/".$YouTubeUsername."/favorites";
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->content->attributes();
$videoURL = $attrs['url'];
$videoURL = preg_replace('/\?.*/', '', $videoURL);
$videoURL = str_replace("/v/","/embed/",$videoURL);
$videoTitle = $media->group->title;
echo "<iframe class='youtube-player' width='300' height='225' src='$videoURL'></iframe>\n";
echo "<br>\n";
}
?>
You should be validating the result of $sxml = simplexml_load_file($feedURL); per the Google error validation docs. Then you can print out the actual message that comes along with the 403 code, or possibly decide to retry the request. If it's a random occurrence my guess is a quota limit issue, but the actual error information will likely tell you exactly what you want to know.
MYUSERNAME is not a valid username. Add your own youtube username!
When I call your feed URL in browser (https://gdata.youtube.com/feeds/api/users/wfptv/favorites) I receive this error:
Favorites of requested user are not public.
Make your feed public, and the failure should be gone.