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
Related
I’m trying to call a URL and read its content using php.
when I place the url directly in the browser It works, but when I use php it returns empty string.
here’s my code:
$url = "https://www.instagram.com/instagram/?__a=1"
$json = file_get_contents($url);
$res= json_decode($json);
var_dump($res);
Does anyone have an idea why I can’t read the file with PHP?
Thank you,
So, I have this xml file:
xml
I use this code to get this xml on php with soap
$response = $clientrepasse->__soapCall("GetSchema", array($paramsrepasse));
$return = $clientrepasse->__getLastResponse()
When I show this $return with my print_r function I got this
return
When I use function var_dump it shows that the $return is a string(40000) positions.
I tried:
$xml = simplexml_load_string($return);
When I print $xml it's empty, I need to transform that string to xml and then to json, or something like that, because I need to work on that xml.
Any help will be appreciated. Thank you and sorry about my english.
Your XML has namespaces. simplexml does not load XMLs into an XML object when it has namespaces. You have to register your namespace to be able to load the XML using simplexml_load_string.
Check the link below:
XML to JSON
XML to JSON
Post XML to get the answer specific to your XML .
You shouldn't need to call __getLastResponse(). It gives you the raw HTTP body as a string, which isn't what you want.
This should be all you need:
$response = $clientrepasse->GetSchema($paramsrepasse);
print_r($response);
You don't need to work with XML. $response will be a PHP object that you can work with straight away.
Note that you also don't need to call __soapCall() directly either.
So I am trying to get some information from a JSON file. But for some reason there is no actual response with the information that I need.
This is the code im running.
$json_object = file_get_contents('http://steamcommunity.com/profiles/'.$steamID.'/inventory/json/730/2');
$json_decoded = json_decode($json_object);
echo $json_decoded->success;
I get the steamID from a cookie. But if you want to see how the JSON looks, then you can check out this link:
http://steamcommunity.com/profiles/76561198031313244/inventory/json/730/2
The problem is that the URL you are checking is redirected to another URL, file_get_contents() doesn't support following redirects AFAIK, so you should better use cURL
Check this answer https://stackoverflow.com/a/4324018/5658508
the problem is like the others tell you is in this link http://steamcommunity.com/profiles/76561198031313244/inventory/json/730/2
i just monitor the response, so when you visit the link you get a 302 Moved Temporarily http response to the new link which is http://steamcommunity.com/id/SANDISS/inventory/json/730/2
you can try to get contents using file_get_contents if you have the link not just a steam id, or use curl library
I'm trying to read aliexpress.com deals page via php. I'm not able to get the details of the page in output.
Is there a way I can get the details.
Below is the code.
<?php
include('simple_html_dom.php');
$url = 'http://activities.aliexpress.com/superdeals.php';
$xml = file_get_html($url);
//$file = 'output1.txt';
$element = $xml;
echo $element;
?>
This website used AJAX
There are two solutions :
- Make the same request as Javascript
- Using a tool like Phantomjs
If you look at requests, you will find easily that a GET request is made and return all information in JSON.
So you need to find by yourself the link or use third party library + tools.
EDIT:
You can use your web browser to get the link (I don't give you it because i think stackoverflow is not for that) with firebug or if you're using chrome, in network tab search for the JSON.
$url = "....";
$str = file_get_contents($url);
if($str) {
$json = json_decode($str, true); // json is an array
// ... do what you need
}
I recommend to use curl instead of file_get_contents for many reasons.
Or you can use Phantomjs (it's really more difficult) and get a "HTML snapshot" and then use DOM or XPATH to get what you need, but you must run Phantomjs and use a third party library for communicate with it.
i am kind of new to API thing, and i need help understanding on what exactly is happening with the below Code.
$address = 'Bhatkal, Karnataka, India';
$requestUrl = 'http://maps.google.com/maps/geo?output=xml&key=aabbcc&oe=utf-8&q='.urlencode($address);
$xml = simplexml_load_file($requestUrl);
i understand that HTTP is capable of sending Request and getting response in return isn't it? what i am unable to understand is the third and last function that is $xml = simplexml_load_file($requestUrl); when i do a print_r($xml) i get an object in return which prints all the object details i got back as response,
how does the function process the
URL?
does it use CURL (i have very less idea about what is CURL).
and where do i look up for Google Maps API URL?
That function does not process the request (nor the URL), only the response, Google processes the URL that, the function just "visit's" it. You can do as well: here. The XML file you see here is ending up in the variable $xml, parsed.
EDIT: the URL in this post is not working too well, because of the key parameter
simplexml_load_file internally uses the fopen wrapper and opens the remote xml that would be produced by the url and then converts into an array for php to easily use.
The response object will help you to extract the data from the response.
Check out the details of Google Maps API