Hey i have problem i need from one json get information to another json link.
I need get all(maxResults) videoId from this link below
https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=UCynfZM0Edr9cA4pDymb2rEA&maxResults=20&key=AIzaSyDVTF2abNVa5pRitb8MVz1ceJFhE-2y_qk
to this link below in this area [NEED HERE videoId with , each]
https://www.googleapis.com/youtube/v3/videos/?id=[NEED HERE videoId with , each]&part=statistics&key=AIzaSyDVTF2abNVa5pRitb8MVz1ceJFhE-2y_qk
All code
<?php
$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=UCynfZM0Edr9cA4pDymb2rEA&maxResults=20&key=AIzaSyDVTF2abNVa5pRitb8MVz1ceJFhE-2y_qk'));
$url = 'https://www.googleapis.com/youtube/v3/videos/?id=[NEED HERE IDS]&part=statistics&key='.$API.'';
$videoViews = json_decode(file_get_contents($url));
foreach($videoList->items as $item){
//Shows embed videos from channels
if(isset($item->id->videoId)){
echo '<div class="video">
<iframe width="280" height="150" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe>
<h5>'. $item->snippet->title .'</h5>
</div>';
}
}
?>
i need look like this 3 videoId added but from first json information
https://www.googleapis.com/youtube/v3/videos/?id=w_TLR7K_g98,H5_LI7caH1M,ishpS2v9uvo&part=statistics&key='.$API.'
Loop through all the items, and put the video IDs into an array. Then use implode() to combine them into a comma-separated string.
$videoIDs = array();
foreach ($videoList->items as $item) {
if(isset($item->id->videoId)){
$videoIDs[] = $item->id->videoId;
}
}
$videosString = implode(",", $videoIDs);
$url = 'https://www.googleapis.com/youtube/v3/videos/?id=' . $videosString . '&part=statistics&key='.$API;
In return for this code, can you please tell me why you put .'' at the end of the $url assignment? I see this frequently and I never understand why people do it.
Related
I am trying to get all the description from this eBay url: https://www.ebay.com/itm/Front-strut-spacers-30mm-for-Ford-Focus2-C-Max-Focus3-Kuga-Escape-Lift-Kit/112460641185?epid=19025000547&hash=item1a2f2d33a1:g:0IYAAOSw1m9atFcz. Here is a screenshot:
The highlighted text is what I am trying to get using the div id: ds_div. However When I debug it it has no value. Here is my code:
$description = $html->find("div[id=ds_div]", 0);
var_dump($description);
if($description != null){
$item['description'] = $description->plaintext;
}else{
$item['description'] = '';
}
Try this May be this will helps to you,
foreach ( $html->find('td div#ds_div') as $element ) {
echo $element->plaintext . '<br>';
}
There actually is no element with id ds_div on that page, that's why your query returns nothing. There is however an iframe on that page that contains the element you're looking for. Get the URL of that iframe, parse/scrape the source of that and you should get your description.
I'm working with a WordPress plugin that outputs a text link, but the user inputs the link from an 3rd party site. the links are youtu.be format, I need the video's ID. I have tried this method but I'm not getting it so far
original code:
if($video_link != "") {
echo '<p>';
echo 'Please visit : Multimedia link for more photos and information' ;
echo '</p>';
}
Output link :
http://youtu.be/abcdefghijkl
tried this, can't get it to work:
if($video_link != "")
{
$url = $_GET['url'];
$video_id = substr( parse_url($url, PHP_URL_PATH), 1 );
echo '<iframe width="560" height="315" src="https://www.youtube.com/embed'.$video_id.'" frameborder="0" allowfullscreen></iframe>' ;
}
Output Iframe does not work :
EDIT: Ignore my previous answer, your parse works fine. You just forgot the / after 'embed' in your iframe src attribute.
Or if you want, you can just remove the substr part in your parse (which is what strips the slash)
$video_id = parse_url($url, PHP_URL_PATH);
The script I am using to pull in the feed titles is:
<?php
function getFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a> </li>";
$i++;
if($i==5) break;
}
echo "</ul>";
}
?>
I would like to pull in the images for each title/article and place them next to the title.
The float part is easy. I'm having trouble getting the actual image in. I've tried that mark like this: <img src="$entry->image" />, but it didn't work.
How would I go about this please?
As the answer to random's suggestion:
I'm using $item['description'] to represent the description string.
Then match for img tag
Output image tag
Then remove the image tag from the original $content and output that, you're left with just the description text
<?php
$content = $item['description'];
preg_match('/(<img[^>]+>)/i', $content, $matches);
echo $matches[0];
echo str_replace($matches[0],"",$content);
?>
When displaying the feed contents, variables such as $entry->link and $entry->title work because they are valid, present and required elements in a standard RSS feed item.
To call $entry->image would require the source RSS to use and populate that optional element.
Some feeds may include that data, but most will not.
Alternatively, you can write your own function or method to scan the contents of the description element and find any suitable image to include as you need.
I want to replace in post and archive custom field the youtube url with php.
From: http://www.youtube.com/watch?v=FKAjQfL31Dw To:
http://www.youtube.com/v/FKAjQfL31Dw
My code is:
<?php if ( get_post_meta($post->ID, 'ixosrip', true) ) { ?>
<embed style="width:150px;height:25px;" allowfullscreen="false" type="application/x-shockwave-flash" src="http://www.youtube.com/v/<?php echo get_post_meta($post->ID, "ixosrip", $single = true); ?>&ap=%2526fmt%3D18&autoplay=0&rel=0&fs=1&color1=0xC0C0C0&color2=0xFFFFFF&border=0&loop=0">
<?php } else { ?>
<em>No sound</em>
<?php } ?>
Current i use a javascript, taked from here: find all youtube links with js (jquery) / But its loads very slow my site.
Is there any way to do this with php in the custom field?
Thank you.
David.
If you can iterate over your custom fields, just do it with a simple PHP str_replace:
$new_url = str_replace('/watch?v=', '/v/', $old_url);
Where $old_url is your video's current slug.
UPDATED ANSWER: You could parse the URL, grabbing the v component:
parse_str($video_url, $params);
$video_id = $params['v'];
$video_url = 'http://www.youtube.com/v/'.$video_id;
You would put this in your loop or your post page template or whatever, where $video_url is the field containing, well, the YouTube video URL you want to alter.
Aye there,
One thing I can think of is making 2 custom fields where one would be the id and would have a value like 'FKAjQfL31Dw'
...and the other would have a value of either 'v/' or 'watch?v=' depending on which one u choose. (can be done via radio buttons)
so ur code might look something like
<embed style="width:150px;height:25px;" allowfullscreen="false" type="application/x-shockwave-flash" src="http://www.youtube.com/
<?php $key='youtube_format'; echo get_post_meta($post->ID, $key, true); ?>
<?php $key='youtube_id'; echo get_post_meta($post->ID, $key, true); ?>
&ap=%2526fmt%3D18&autoplay=0&rel=0&fs=1&color1=0xC0C0C0&color2=0xFFFFFF&border=0&loop=0">
If your trying to do this in archives, you would most likely add this code to content.php or content-video.php.
I'm trying to set up a php page made up of images from 3 different RSS feeds, in 3 columns. The first feed is from a Wordpress blog, the second from an Etsy store, and the third from a Flickr feed.
What I would like to do is grab the link to the images from the first 3 items in each feed.
Relevant information:
The Wordpress feed puts the link in the description, which is formatted as CDATA.
The Etsy feed puts the image link as the first item in the description (E.g. <img src="http://ny-image2.etsy.com/il_155x125.126568958.jpg" />), but also has it in a <g:image_link> tag.
The Flickr feed has the link in the description, but it comes third after links for the user's profile and a link to the photo page. There is also <media:content url="http://farm5.static.flickr.com/4016/4377189674_d6f3aafa81_m.jpg"
type="image/jpeg"
height="159"
width="240"/>.
I've read over the basics of both php and simplexml but it seems what I'd like to do is too complicated for me to figure out on my own. I'd prefer to have a separate functions.php file so I only have to call the function on the web page.
ETA:
I've got the images for the Etsy feed pulled using
<?php
function getEtsyFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "
<li>
<a href='$entry->link'><img src=" . $entry->children('g', true)->image_link . " /></a>
</li>";
}
echo "</ul>";
}
?>
and the images from the Flickr feed pulled using
<?php
function getFlickrFeed($feed_url) {
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
echo "<ul>";
foreach($x->channel->item as $entry) {
echo "
<li>
<a href='$entry->link'><img src=" . $entry->children('media', true)->thumbnail->attributes()->url . " /></a>
</li>";
}
echo "</ul>";
}
?>
I'm still not sure what to do about the blog feed, or how to only show the first 3 images without breaking the code that I do have.
You should try MagPie.
http://magpierss.sourceforge.net/