Youtube oEmbed html has an extra ')'? - youtube

I am not 100% sure if this is something wrong with Youtube's endpoint of if i am doing something wrong.
The problem came about when I was embedding a Youtube video in WordPress. I did all the debugging through WordPress core and narrowed it down to the response from the Youtube endpoint that returns the oEmbed from youtube.
Endpoint:
https://www.youtube.com/oembed?maxwidth=640&maxheight=960&url=youtu.be%2FI0dQx4SNSwE&format=json
Response (raw):
{"thumbnail_height": 360, "width": 640, "thumbnail_width": 480, "provider_url": "http:\/\/www.youtube.com\/", "html": "\u003ciframe width=\"640\" height=\"360\" src=\"http:\/\/www.youtube.com\/embed\/I0dQx4SNSwE?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e)", "height": 360, "type": "video", "version": "1.0", "title": "Why Do We Yawn?", "author_name": "AsapSCIENCE", "thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/I0dQx4SNSwE\/hqdefault.jpg", "provider_name": "YouTube", "author_url": "http:\/\/www.youtube.com\/user\/AsapSCIENCE"}
Response: (formatted)
{
"thumbnail_height": 360,
"version": "1.0",
"provider_name": "YouTube",
"thumbnail_url": "http://i1.ytimg.com/vi/I0dQx4SNSwE/hqdefault.jpg",
"title": "Why Do We Yawn?",
"html": "<iframe width=\"640\" height=\"360\" src=\"http://www.youtube.com/embed/I0dQx4SNSwE?feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>)",
"provider_url": "http://www.youtube.com/",
"type": "video",
"height": 360,
"author_url": "http://www.youtube.com/user/AsapSCIENCE",
"thumbnail_width": 480,
"author_name": "AsapSCIENCE",
"width": 640
}
As you can see at the end of the 'html' attribute there is an extra "/iframe\u003e)"
Am I doing something wrong or is there something wrong with Youtube? I am at a loss for words. I would really like to think that Youtube would be smart enough to not return something like this, so I have to think it is something I am doing wrong...

See this similar problem, looks like a known bug:
https://productforums.google.com/forum/#!topic/youtube/1jGhK-g8r4E

Related

How to retrieve game title bound to video [duplicate]

This question already has answers here:
Youtube API Retrieve Live Stream Game Title
(2 answers)
Closed 1 year ago.
Does anyone know how to get the game title assigned to video via the Youtube API?
Game title screenshot from YT web. Here I need to get the Call of Duty game from this video:
Documentation doesn't have any information regarding game title in the video resource: https://developers.google.com/youtube/v3/docs/videos
API query with the broadest content settings returns this:
{
"kind": "youtube#videoListResponse",
"etag": "0KGf7UH0NGSsvuQJqAEX4e1mE00",
"items": [
{
"kind": "youtube#video",
"etag": "atR4AXswOz04SvjBEFuPTUpgEKo",
"id": "Tn2TgqkrCng",
"snippet": {
"publishedAt": "2016-09-23T16:31:31Z",
"channelId": "UCv2IxyoJetx3b3nPbHJbx3g",
"title": "Batman: The Telltale Games Series [#7][Epizod 2 FINAŁ]",
"description": "Wrzućcie like'a na facebooku: ",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Tn2TgqkrCng/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/Tn2TgqkrCng/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/Tn2TgqkrCng/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/Tn2TgqkrCng/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/Tn2TgqkrCng/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "Tivolt",
"tags": [
"tivolt",
"let's play",
"zagrajmy w",
"gameplay",
"gry",
"zagrajmy",
"vlog",
"fajne",
"gta",
"batman",
"telltale"
],
"categoryId": "20",
"liveBroadcastContent": "none",
"localized": {
"title": "Batman: The Telltale Games Series [#7][Epizod 2 FINAŁ]",
"description": "Wrzućcie like'a na facebooku: "
},
"defaultAudioLanguage": "pl"
},
"status": {
"uploadStatus": "processed",
"privacyStatus": "public",
"license": "youtube",
"embeddable": true,
"publicStatsViewable": true,
"madeForKids": false
},
"statistics": {
"viewCount": "33035",
"likeCount": "1681",
"dislikeCount": "23",
"favoriteCount": "0",
"commentCount": "131"
},
"player": {
"embedHtml": "<iframe width=\"480\" height=\"270\" src=\"//www.youtube.com/embed/Tn2TgqkrCng\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
},
"topicDetails": {
"relevantTopicIds": [
"/m/02vxn",
"/m/025zzc",
"/m/0403l3g"
],
"topicCategories": [
"https://en.wikipedia.org/wiki/Action_game",
"https://en.wikipedia.org/wiki/Film",
"https://en.wikipedia.org/wiki/Role-playing_video_game"
]
},
"recordingDetails": {}
}
],
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
}
}
As you can see, there is no info about game title. Has anyone struggled with this and knows the way how to do it?
Someone has already posted the same question here, but it looks like everyone misunderstood him, there is no correct answer and I have no rep to comment in this thread.
As people noticed, there isn't any YouTube Data API v3 endpoint providing you the game associated with the YouTube video.
However by downloading the video webpage and looking for in the source code of the webpage we can find it. Here is a Python 3 script retrieving the game title associated with the YouTube video if there is any:
import urllib.request
def getURL(url):
return urllib.request.urlopen(url).read().decode('utf-8')
videoId = 'oua2xCWTK48'
url = 'https://www.youtube.com/watch?v=' + videoId
content = getURL(url)
prefix = '}]},"title":{"simpleText":"'
if prefix in content:
gameName = content.split(prefix)[1].split('"')[0]
print(gameName)

YouTube API thumbnail urls not resolving

I am hoping this is a one off, but today I came across a video that reports the following when calling the "Videos: list" endpoint by a videoId:
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/maxresdefault.jpg",
"width": 1280,
"height": 720
}
}
... but neither the "maxres" or "standard" urls render an image (they 404 and render the nasty YouTube default grey image). Usually when those sizes were not available, those objects were not in the array.
Can anyone shed some light on this?
EDIT **
I should mention that the remainder of the thumb urls work as expected and embedding of the video fails to render a poster image with the exception of Chrome on desktop (which uses WEBP)

Is possible somehow explore youtube videos by hashtag?

I have been looking at the YouTube API and I am wondering if it is possible somehow search YouTube videos by hashtags e.g.
I want explore YouTube video for hashtag #funny
I have read YouTube API documentation but I haven't found anything.
Search: list
Returns a collection of search results that match the query parameters specified in the API request. By default, a search result set identifies matching video, channel, and playlist resources, but you can also configure queries to only retrieve a specific type of resource.
In my experience this is a full text search on title and description of the video so assuming your hash tags are in the description you should be able to search on them.
Request
GET https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&q=%23funny&key={YOUR_API_KEY}
Response
{
"kind": "youtube#searchListResponse",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/wR5yPzOxAnu-87xJGtSkLXz_78Q\"",
"nextPageToken": "CBkQAA",
"regionCode": "DK",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 25
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"RmznBCICv9YtgWaaa_nWDIH1_GM/IByts9zZTVNkc5EfbIDTKpE6pf8\"",
"id": {
"kind": "youtube#video",
"videoId": "DODLEX4zzLQ"
},
"snippet": {
"publishedAt": "2017-06-17T10:03:47.000Z",
"channelId": "UCKy3MG7_If9KlVuvw3rPMfw",
"title": "WATCH and TRY TO STOP LAUGHING - Super FUNNY VIDEOS compilation",
"description": "Can you hold your laugh while watching these clips? :) Mix of best and funniest animal & human fails. We bet you will lose this laugh challenge. Anyways, what is your favorite clip? :) Hope...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/DODLEX4zzLQ/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/DODLEX4zzLQ/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/DODLEX4zzLQ/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Tiger Productions",
"liveBroadcastContent": "none"
}
},
This is the video it returned WATCH and TRY TO STOP LAUGHING - Super FUNNY VIDEOS compilation #funny is in the description.
You can try it yourself here Google Apis Explorer

Get all playlist ids from channel id - youtube api v3

I am currently learning the use of the youtube api. I want to retrieve all playlists id from a channel id. I read through the documentation and saw that I can use youtube.channels.list for such task. I did basic testing on the api_page. Still, I am not able to figure what params to use to get the playlist id. How can I retrieve all playlist ids from a given channel id?
https://www.googleapis.com/youtube/v3/channels?part=id&id=UCF0pVplsI8R5kcAqgtoRqoA&key={YOUR_API_KEY}
A simple way :
With the YouTube API v3 with the ressource playlists.list
Use this parameters to get the playlists ID of a channel :
part: 'snippet'
channelId: 'UCBkNpeyvBO2TdPGVC_PsPUA'
https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCBkNpeyvBO2TdPGVC_PsPUA&key={YOUR_API_KEY}
The output :
"items": [
{
"kind": "youtube#playlist",
"etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/K21sgPQuMRCjhSMBjm3v3n5tl1o\"",
"id": "PL2qcutlDmS0CnyV8Jcbl2d7yFxd2iGg67",
"snippet": {
"publishedAt": "2014-07-08T03:13:37.000Z",
"channelId": "UCBkNpeyvBO2TdPGVC_PsPUA",
"title": "These Things Happen Series",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/93mgU_VXZrA/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "GEazyTV"
}
},
{
"kind": "youtube#playlist",
"etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/5ifuvTYKbyV6DUPqbTa2bnO2jWY\"",
"id": "PL2qcutlDmS0B0jwHOQYzgRhJpnxDwPBHc",
"snippet": {
"publishedAt": "2014-06-05T07:36:58.000Z",
"channelId": "UCBkNpeyvBO2TdPGVC_PsPUA",
"title": "B-Sides",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/f7Ua9wKvVtI/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "GEazyTV"
}
},
...
This is a sample example with a random channel.
If you don't know how to get the channelID of a channel use ressource channels.list:
With this parameters to get the video ID of a playlist :
part: 'id'
forUsername: 'channel_name'
https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=GEazyTV&key={YOUR_API_KEY}
"items": [
{
"kind": "youtube#channel",
"etag": "\"PSjn-HSKiX6orvNhGZvglLI2lvk/vIwM6ev74Om0AOupX26jJoEDELU\"",
"id": "UCBkNpeyvBO2TdPGVC_PsPUA"
}
I'm not sure how I came across this solution, but I've found that if you follow these steps then you can retrieve the playlistID to use:
Create an API Key using the Google API Console.
Use
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&key=[KEY FROM GOOGLE API CONSOLE]&id=[CHANNEL ID]
where you are replacing everything, including the brackets, with the corresponding info (I find channel ids are easy to come by since they are normally in the URL. The PlaylistID is the one that tends to be difficult).
The resulting feed from the URL in step 2 should contain an uploads object, containing the playlistID which is used in the URL in step 4.
Use
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=[PLAYLIST ID RETRIEVED IN STEP 3 HERE]&key=[KEY FROM GOOGLE API CONSOLE]
The link from step 4 is what should end up being used in the app.
This works for me every time, and I integrate the YouTube v3 API in many apps. I completely agree with #Utkanos' comment that while #mpgn's answer works sometimes, it certainly doesn't work for all channels.
Youtube Api v3 Channel Playlist video max 50
This url format work
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=[]&key=[]&maxResults=50

retrieve twitter pictures or videos when using an specific hashtag

I'm looking to create a single page for a school event where basically I would like to display all the pictures of tweets with an specific hashtag, and if possible any youtube or vimeo video.
I'm been taking a look to the twitter API, however I cannot find an starting point, does anyone has any idea about to approach this?
I would appreciate any help.
Thanks in advance.
You may find this article helpful to grab pictures mentioned in a tweet via Twitter's JSONP feed for a specific search term or hashtag.
This is the part of the feed for a single Tweet containing the media object that holds info about images -
"text": "#Photos on Twitter: taking flight http://t.co/qbJx26r",
"entities": {
"media": [
{
"id": 76360760611180544,
"id_str": "76360760611180544",
"media_url": "http://p.twimg.com/AQ9JtQsCEAA7dEN.jpg",
"media_url_https": "https://p.twimg.com/AQ9JtQsCEAA7dEN.jpg",
"url": "http://t.co/qbJx26r",
"display_url": "pic.twitter.com/qbJx26r",
"expanded_url": "http://twitter.com/twitter/status/76360760606986241/photo/1",
"sizes": {
"large": {
"w": 700,
"resize": "fit",
"h": 466
},
"medium": {
"w": 600,
"resize": "fit",
"h": 399
},
"small": {
"w": 340,
"resize": "fit",
"h": 226
},
"thumb": {
"w": 150,
"resize": "crop",
"h": 150
}
},
"type": "photo",
"indices": [
34,
53
]
}
],
"urls": [
],
"user_mentions": [
],
"hashtags": [
]
}
There doesn't appear anything similar for videos but you can look into the "urls" array within "entities" to check for references to YouTube video links.
Sorry this isn't a direct answer.
I recently did something similar with Instagram (displaying images based off hastags).
I used a jQuery plug in that was almost too easy to set up. You basically just fill in what hashtag you want, and the limit of photos to display in a simple function and it's good to go.
Perhaps there is something similar for twitter?
Best of luck.

Resources