Lost in the YouTube API - php

I've been working with a couple of API's before like Vimeo, Dribbble and Twitter. Now I am trying out YouTube's API. But the complexity of the API gets me lost.
I've been going through parts of it and reading up on a couple of tutorials but can't seem to find what I want.
They say something about zend_gdata but I don't understand what that has to do with YouTube's API and can't seem to get it work either.
This is what I want to accomplish:
Get video data for each video from [playlist] by [user]:
Video poster (big thumbnail)
Title
Description
Embed code (iframe probably)
I am using PHP and prefer an output in JSON.
Can you guys point me out where to start (tutorial, which API, ...) to accomplish this rather simple task?
EDIT
Example for Vimeo: http://vimeo.com/api/v2/channel/52750/videos.json
Which URL can I CURL for YouTube to get al videos in a specified playlist?

From Data API Protocol site:
As noted in the previous section, each entry in a user's playlists feed contains a tag that specifies the URL for retrieving the list of videos in the playlist. The following example shows the URL for retrieving a playlist as that URL appears in a playlists feed entry:
<content type='application/atom+xml' src='http://gdata.youtube.com/feeds/api/playlists/8BCDD04DE8F771B2?v=2'/>
So the url is something like this:
http://gdata.youtube.com/feeds/api/playlists/PLAYLISTID?v=2
Update
For JSON format, add &alt=json GET parameter at the end of the url:
http://gdata.youtube.com/feeds/api/playlists/PLAYLISTID?v=2&alt=json

Related

PHP & post Youtube ID to another page

I've been searching for this a lot but have not found exactly what I'm looking for.
So, I have a page (index.php) which displays my YouTube channel's uploaded videos as thumbnails, and either displays them inline above the thumbnails, or as links that redirect to Youtube. What I'd like to do, is to get the video's ID (which is in the a href link) and post it to another page (video.php) that shows the full embedded video (of the ID in question), with title & description. Is this possible to do?
My site is loosely based on this: http://www.yvoschaap.com/youtube.html and I've tried Youmax, but like said, they only play videos inline. I want to pass the ID of a clicked video as a parameter to the video.php page.
Sorry if this is confusing, but I'm still quite new to programming :)
You can look into Youtube Data API.
The main link you will need to retreive a list of all Videos for a channel will be somewhat like:
https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults={number_of_videos_you_want}
It will recieve it's response in JSON Format containing information like your Video ID which you can pass as Parameter to your video.php page

How to embed twitter tweets .. How to catch images from tweets URLs and display the actual images?

I was wondering what kind of method I could use to directly embed videos or pictures contained in twitter tweets directly ... For example .. below is a tweet from OBAMA
President Obama: "Right now, we have a real chance to reduce gun violence in America." http://t.co/tmCoUsPyyB #TimeToAct
The link that starts with htttp:// could be a picture .. How can I actually program it so that tweets are directly displayed with the images from the urls ? I know PHP and I used the twitter API before , but I dont know how I could easily achieve that . Any help would be appreciated
The first step would to to pull the URLs of of the block of text, there is another question that points you how to solve this: Extract URLs from text in PHP
You can then use Embedly or a service like it to pull the metadata associated with that url. Here is an example of the meta data that Embedly will return: http://embed.ly/docs/explore/oembed?url=http%3A%2F%2Ft.co%2FtmCoUsPyyB
The html attribute is what you want to render on your page.
We also have a PHP library you can use as well.
Hope that helps!

SimplePie parsing to Find Youtube Video link

I'm using SimplePie to parse our church RSS Feed which contains weekly sermons, both audio and video. I'm able to get the title and mp3 link, but having a difficult time getting the youtube link. Below is a sample of what is in the XML feed containing the youtube video.
It's using [CDATA]
I'm using $item->get_content(), but that doesn't seem to contain any of the tag data below. The url for the feed is http://lakeforest.org/feed. When I bring this url up in the browser I can see the embedded youtube video.
Any help would be greatly appreciated.
NOTE: - i commented the html below for display only
<!--
<description><![CDATA[Huntersville Campus Mike Moses, Lead Pastor Series Discussion Questions: SHAPE, Part 2 Spiritual Gifts Inventory VIDEO AUDIO]]></description>
<content:encoded><![CDATA[<h3>Huntersville Campus</h3>
<p>Mike Moses, Lead Pastor<br />
Series Discussion Questions: SHAPE, Part 2<br />
Spiritual Gifts Inventory</p>
<h4>VIDEO</h4>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/4Uv8U8c6isg" frameborder="0" allowfullscreen></iframe></p>
<h4>AUDIO</h4>
<img src="http://feeds.feedburner.com/~r/LakeForest/~4/qMoLVpI1tGI" height="1" width="1"/>]]> -->
SimplePie strips out embed, object, iframe etc tags by default as they can be dangerous.
You should ignore them if you want the video back, but be careful with the source url as it could be a security issue.
$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
// Remove these tags from the list
$strip_htmltags = $feed->strip_htmltags;
array_splice($strip_htmltags, array_search('object', $strip_htmltags), 1);
array_splice($strip_htmltags, array_search('param', $strip_htmltags), 1);
array_splice($strip_htmltags, array_search('embed', $strip_htmltags), 1);
array_splice($strip_htmltags, array_search('iframe', $strip_htmltags), 1);
$feed->strip_htmltags($strip_htmltags);
Source
I just noticed your feed URL, that wasn't what I was expecting, I was expecting something like this:
http://gdata.youtube.com/feeds/base/videos?q=painting+miniatures+tutorial&orderby=published&client=ytapi-youtube-search&v=2
That is a search result feed from YouTube which I pass to SimplePie here. Also the rest of your PHP code where you declare $item would be useful. I answered a similar question tonight and basically over the years YouTube has changed their API and feeds, you might have to update to a newer version of their API/feed even if you can find old examples of it working.
SimplePie can handle some if not all YouTube feeds, but there is no guarantee Google (YouTube) will give you a thumbnail and all the metadata they have on YouTube.com. APIs usually make a subset of the data contained in their database available via APIs, they want people to come to their website so they can show them ads and track them better.
Not the answer you want perhaps but without more information, that is the best I can do.
If you want to dig into the feed and get the video URL and then create a player for it, that is non-trivial. You have to use something like simple_html_dom then you need to create a properly formatted iframe or javascript call to create the in browser player. SimplePie doesn't have a get_contents()->video

youtube xml feed for single playlist

Perhaps I am missing something but how does one go about retrieving the xml feed of videos from a single YouTube playlist. I have tried all the ways listed on google and so on but they keep returning an invalid playlist if error even though the id is exactly the one in the youtube url that works on youtube.
Thanks
You can get listing of user's public playlists at:
http://gdata.youtube.com/feeds/api/users/username/playlists?alt=rss&v=2
And you can get xml data for an individual playlist by at:
http://gdata.youtube.com/feeds/api/playlists/AA8A0579E8329C7A?alt=rss&v=2
replace AA8A0579E8329C7A with the playlist-id you want.

Flickr feed problems. how to show all images from a photostream

I am using a bespoke JQuery/PHP script which parses a Flickr feed using SimpliePie and outputs an image gallery.
I have instructed my client to upload there images into their flickr account.
The images are showing but the feed seems to be limiting to 20 images, however, there are 40 images in the stream.
I have checked the API and there doesn't seem to be any paramaters to change this.
Has anyone come across this before, can anyone help me tweak the feed so that it pulls all the images in the photostream?
Here is the Flickr Stream and feed...
http://www.flickr.com/photos/44280289#N04/
http://api.flickr.com/services/feeds/photos_public.gne?id=44280289#N04&lang=en-us&format=rss_200
It appears that they do limit it to the initial 20 photos on flickr
http://www.flickr.com/help/website/
Why do I only see 20 items in RSS
feeds?
Flickr only shows the latest 20 items
in a feed. Because of this, the first
time you connect to a feed you will
only see the most recent items. But if
your RSS reader saves items (as most
do) you will see more than 20 as the
items build up over time.
But you could potentially use the flickr api, particularly http://www.flickr.com/services/api/flickr.photosets.getPhotos.html
Which allows you to get more (You will need to get an API key however)
Edit:
Though I have not personally used it I have read/heard good things about http://phpflickr.com/ which is a flickr api wrapper for php 4 and 5
Edit 2:
Unfortunately I can not comment on your comment but if you take a look at this link from the flickr code blog
http://code.flickr.com/blog/2008/08/25/api-responses-as-feeds/
Some API responses can been provided as feeds so you could try using "&format=feed-rss_200" not sure if it includes getPhotos yet though.
It seems like you want to use the photosets.getPhotos api call. It will give you a maximum of 500 photos.
Here is an example which gives you the url of the photo in url_o
http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&extras=url_o&photoset_id=72157622766901612&api_key=[YOUR APIKEY HERE]
You need an api key to make it work.
You can also get the output as JSON directly by adding &format=json to the url.

Categories