I need to get the XML data from youtube for a particular video(based on ID) and fetch the thumbnail url. I am using PHP.
The code is as follows:
<?php
//$xmlFilePath = 'http://localhost/testFile.xml'; //This works..
$xmlFilePath = 'https://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?v=2';
$dataFromYoutube = file_get_contents($xmlFilePath);
print_r($dataFromYoutube);
?>
I dont get any data. The output is blank. If I load the url 'https://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?v=2' in browser and copy the content to a file(http://localhost/testFile.xml), then the above code works.
I have tried fetching the youtube data using ajax and also simlexml_load_file function in php. But the result is blank/empty for Youtube url. However, I get the data for 'http://localhost/testFile.xml' in both cases.
How can I fetch youtube data using php?
Please help.
well, your code is correct and works fine too. It may be that your apache server is not configured for "https". So just check it once too.
Related
I know that this api is working to get images but how about videos?
https://www.instagram.com/username/?__a=1
I was able to get the thumbnail of the video but not the source or the url itself.
When you make above API call it would return code in it. looks something like this: BWhyIhRDBCw
Whenever your media nodes has "is_video": true you can make following call:
https://www.instagram.com/p/{code}/?__a=1
for e.g.,
https://www.instagram.com/p/BWhyIhRDBCw/?__a=1
This would return another json. which will have video_url you are looking for.
sample:
"video_url": "https://scontent-bom1-1.cdninstagram.com/vp/437699b67172f450331fa732f0777b18/5A7FE0A0/t50.2886-16/20138822_486349355081174_1539674401849475072_n.mp4",
This url working in local machine but not on my remote server.
When i try to hit from remote server its returning html content.
To hit this api simply use volly library it will return json then u can parse json as per your need.
I'm trying to scrape a website (www.glturk.com).
When I run the below link via a browser:
http://www.glturk.com/ajax.aspx?stream=live&type=free&ppoint=ATVTurkiye_LR
I get the following response:
http://38.117.88.248:7777/ATVTurkiye_LR.m3u8?user=sglsxxdewfiduaqygnbfnqwcuc55&session=e0e8f5e6dbfb83be9e4f1155454b43d14130b7e79528a6fbe8dcb832c9f2cef0fbecdaf0092c93ab9826978c8d46626c20ba4293a32569e6e7cfbbd9d61c69ad
The above M3U8 link works perfectly in that instance.
But, if I try to replicate this via a PHP file, I get a very similar result, but that m3u8 link does not work?!
<?php
$channelURL= 'http://www.glturk.com/ajax.aspx?stream=live&type=free&ppoint=ATVTurkiye_LR';
$actualLink = file_get_contents($channelURL, TRUE);
echo $actualLink;
?>
The result I get is:
http://38.117.88.249:7777/ATVTurkiye_LR.m3u8?user=sglspoqmpdi2tltn0lynorytlnvi&session=08e5fd64dca2f17d9e4f1155454b43d136fa14cb989a57687b29865e85d60962253ac665a78595d7c5529895b22236c2f32018226b4a15e9b8327f16597d3505
This m3u8 does not work though, I can't understand why.
Working (via direct link through browser):
http://38.117.88.248:7777/ATVTurkiye_LR.m3u8?user=sglsxxdewfiduaqygnbfnqwcuc55&session=e0e8f5e6dbfb83be9e4f1155454b43d14130b7e79528a6fbe8dcb832c9f2cef0fbecdaf0092c93ab9826978c8d46626c20ba4293a32569e6e7cfbbd9d61c69ad
Not Working (via PHP):
http://38.117.88.249:7777/ATVTurkiye_LR.m3u8?user=sglspoqmpdi2tltn0lynorytlnvi&session=08e5fd64dca2f17d9e4f1155454b43d136fa14cb989a57687b29865e85d60962253ac665a78595d7c5529895b22236c2f32018226b4a15e9b8327f16597d3505
Any advise would be appreciated :) Thank you!
I have signed up to a synonym API.. see the details on this page
I am having trouble implementing this in my php code.
If I copy and paste the link into the web browser, I can see the results no problem.
Instead of typing the word in manually, I wish to have a variable in the link with the relevant word i.e. $variable_with_word_stored as shown below.
http://words.bighugelabs.com/api/2/xxxxxxxx/$variable_with_word_stored/php
//format could be php (I would unserialize)..or json..I could decode it?
Any ideas guys? Thanks.
It sounds like you mean you want the result from calling that webpage and store it in a variable. What you should be looking to do is sending a http get request to that page within the code.
Check out using curl with php, you can send a http request to your requested url, capture the result back and parse it through json_decode
http://php.net/manual/en/curl.examples-basic.php
try it like this, maybe that you dont need curl:
$key = "xxxxxxxx";
$word = "love";
echo file_get_contents("http://words.bighugelabs.com/api/2/$key/$word/php");
I need some album covers for my PHP website but something is not working anymore.
I was using a JSON to get Album ID and then i was using this id to get the album cover.
My problem is that i try to decode a json from website but i don't get any result anymore (it was working before ...).
Here is the code (getting JSON and decoding it) :
$req="http://api-v3.deezer.com/1.0/search/track/?q=".$deezer."&index=0&nb_items=8&output=json";
$result = file_get_contents($req);
$testjson=json_decode($result,true);
I think you are using an old code of Deezer api (1.0 and I don't get any JSON from your url).
Try to change $req by :
$req="http://api.deezer.com/2.0/search/album/?q".$deezer."&index=0&nb_items=8&output=json";
Then, some code are missing and are important to change too.
When you try to get your image, don't forget to change the url too with that version (2.0).
You can find more information on Deezer Api : here.
I'm trying to retrieve an webpage that has XML data using file_get_contents().
$get_url_report = 'https://...'; // GET URL
$str = file_get_contents($get_url_report);
The problem is that file_get_contents gets only the secure content of the page and returns only some strings without the XML. In Windows IE, if I type in $get_url_report, it would warn it if I want to display everything. If I click yes, then it shows me the XML, which is what I want to store in $str. Any ideas on how to retrieve the XML data into a string from the webpage $get_url_report?
You should already be getting the pure XML if the URL is correct. If you're having trouble, perhaps the URL is expecting you to be logged in or something similar. Use a var_dump($str) and then view source on that page to see what you get back.
Either way, there is no magic way to get any linked content from the XML. All you would get is the XML itself and would need further PHP code to process and get any links/images/data from it.
Verify if openssl is enable on your php, a good exemple of how to do it:
How to get file_get_contents() to work with HTTPS?