How to get a youtube channelid from the channels link programmatically - javascript

I need to get the channelid of a youtube channel (to use the youtube data api) with the link of the channel.
The problem is that there are a few types of links for a youtube channel.
The first one is where the channel id is in the link:
https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw
This is ok because i can just extract the channelid from the link.
The problem comes with the second one:
https://www.youtube.com/#PewDiePie
This is the link you normally get for a youtube channel and it has a # instead of the channelid.
When i use the youtube api to get the channel id of a not so popular channel i get the wrong results:
https://www.googleapis.com/youtube/v3/search?part=snippet&q=#pewdiepie6&type=channel&key=[API_KEY]
I would like to get the channel info and channelid for the channel with the #pewdiepie6 handle.
But i get the more popular channel with the #pewdiepie6802 handle.
Also, i get more than 1 channel as a result.
{
"kind": "youtube#searchListResponse",
"etag": "ecshCA97Jd0CuntIj9NzN3UF37U",
"nextPageToken": "CAUQAA",
"regionCode": "CH",
"pageInfo": {
"totalResults": 51,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "x4yStPuXhfUUIaev-BCMiq1JQ4E",
"id": {
"kind": "youtube#channel",
"channelId": "UCnJABWFF_vWuPgPjGjVJF8A"
},
"snippet": {
"publishedAt": "2018-03-02T14:07:51Z",
"channelId": "UCnJABWFF_vWuPgPjGjVJF8A",
"title": "PewDiePie",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu84CCwyUjzgQkuvN7ms2JUCU0EgofxrTdhZLZKs=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu84CCwyUjzgQkuvN7ms2JUCU0EgofxrTdhZLZKs=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu84CCwyUjzgQkuvN7ms2JUCU0EgofxrTdhZLZKs=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "PewDiePie",
"liveBroadcastContent": "none",
"publishTime": "2018-03-02T14:07:51Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "2et4mkoeeilV2DhJRH7M5xlgnuQ",
"id": {
"kind": "youtube#channel",
"channelId": "UCSn7KcaNdOrVf4aH-6OdFMg"
},
"snippet": {
"publishedAt": "2017-04-23T06:06:06Z",
"channelId": "UCSn7KcaNdOrVf4aH-6OdFMg",
"title": "PewDiePie 6",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu8OB0Z-JNTYnB2Q0KLoV6LjvpUYpYfN0sfAMgfT=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu8OB0Z-JNTYnB2Q0KLoV6LjvpUYpYfN0sfAMgfT=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu8OB0Z-JNTYnB2Q0KLoV6LjvpUYpYfN0sfAMgfT=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "PewDiePie 6",
"liveBroadcastContent": "none",
"publishTime": "2017-04-23T06:06:06Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "88l8OAYbY0S8XY9NbWcqW2QtJJ4",
"id": {
"kind": "youtube#channel",
"channelId": "UCpqNuOLjibXIO43tJbZ-s3w"
},
"snippet": {
"publishedAt": "2017-06-17T21:56:28Z",
"channelId": "UCpqNuOLjibXIO43tJbZ-s3w",
"title": "PewDiePie",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu-GIq-DWy8zPGzPmQnb5LHvR_MlnlK3t-G5-45i=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu-GIq-DWy8zPGzPmQnb5LHvR_MlnlK3t-G5-45i=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu-GIq-DWy8zPGzPmQnb5LHvR_MlnlK3t-G5-45i=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "PewDiePie",
"liveBroadcastContent": "none",
"publishTime": "2017-06-17T21:56:28Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "MItPbLglqDfEkQ-fXSbQef7js2c",
"id": {
"kind": "youtube#channel",
"channelId": "UCQXfsdNRgLL0Cz67stMFNVQ"
},
"snippet": {
"publishedAt": "2018-03-31T09:27:20Z",
"channelId": "UCQXfsdNRgLL0Cz67stMFNVQ",
"title": "Marian Pewdiepie 6",
"description": "Nu voi mai posta mai mult de 1 an căci nu prea am vhef Dar totuși dați subscribe.",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu9G8MRCxqrk5dCx9T6lxjWpaAL62QuD54LGpgV6=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu9G8MRCxqrk5dCx9T6lxjWpaAL62QuD54LGpgV6=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu9G8MRCxqrk5dCx9T6lxjWpaAL62QuD54LGpgV6=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "Marian Pewdiepie 6",
"liveBroadcastContent": "upcoming",
"publishTime": "2018-03-31T09:27:20Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "_yNYVPOhK2ZEn0yq580TFty6AHU",
"id": {
"kind": "youtube#channel",
"channelId": "UCR8SFIzFOxf50N0lYER8_-w"
},
"snippet": {
"publishedAt": "2019-03-09T20:56:38Z",
"channelId": "UCR8SFIzFOxf50N0lYER8_-w",
"title": "Go sub to Pewdiepie 6",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu_3fwpv9uhEyzb_bUgNuzETQHpdgvKv-xDSYQ=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu_3fwpv9uhEyzb_bUgNuzETQHpdgvKv-xDSYQ=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AMLnZu_3fwpv9uhEyzb_bUgNuzETQHpdgvKv-xDSYQ=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "Go sub to Pewdiepie 6",
"liveBroadcastContent": "none",
"publishTime": "2019-03-09T20:56:38Z"
}
}
]
}
I also tried to extract the channelid out of the javascript of the page but using Beautiful Soup.
But i could not get it to return the right javascript.
There is also a second api link with the forUsername parameter.
But with this link it tries to look for a user which uploads on a channel which is not what i want.
At the end of the day i want a safe method to get the channel id with the channels link.
https://www.youtube.com/#pewdiepie6
=> UCl-0ct6u2AAfsqGGgVh5dEw
(I got this manually out of the #pewdiepie6 javascript file from the page at externalid)

Related

Is it possible to search multiple channels with one query?

I want to search multiple channels via the Channels.id parameter for videos with one query.
For example:
My request URL is: https://youtube.googleapis.com/youtube/v3/search?part=snippet&channelId=UCSzAsgKDpNkch1eRA9w5nww%20%2B%20UCyCBf6asf89aQJaSXuAuTsg&q=Bitcoin&type=video&key=[YOUR_API_KEY]
The answer is:
{
"kind": "youtube#searchListResponse",
"etag": "DCv8u79rz_Z5yPVlSxf2awnPWTQ",
"regionCode": "DE",
"pageInfo": {.
"totalResults": 0,
"resultsPerPage": 0
},
}, "items": []
}
Is it not possible with YouTube Search API V3 in 2022 to search multiple Channel.id's for a topic with one request?
I have already tried several combining operators.
Am i doing something wrong?
No, it's not possible in the way you're trying - when using multiple channels (or multiple values in a field/parameter for that matter), values are comma-separated, but, even with this fix to the request, the API does not bring any results.
See demo
Instead, you should make one request per channel.
Search with channelId UCSzAsgKDpNkch1eRA9w5nww - see demo # 1
Search with channelId UCyCBf6asf89aQJaSXuAuTsg - see demo # 2
If instead, you want to search channels that matches your criteria (Bitcoin in region DE), then see this sample
Results (summarized):
{
"kind": "youtube#searchListResponse",
"etag": "MF1reS3I3oQvjOtYP2oZ8FI9sJ8",
"nextPageToken": "CAUQAA",
"regionCode": "DE",
"pageInfo": {
"totalResults": 19344,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "pBsNFEU4k7Fc5rWvL9z8woS_0ew",
"id": {
"kind": "youtube#channel",
"channelId": "UCwdYYyyX9V3u_b6URNpBh_w"
},
"snippet": {
"publishedAt": "2020-05-24T15:48:35Z",
"channelId": "UCwdYYyyX9V3u_b6URNpBh_w",
"title": "Bitcoin verstehen",
"description": "Was ist Bitcoin und wieso benötigen wir ihn? In diesem Podcast bringen wir neugierigen Einsteigern und auch Fortgeschrittenen ...",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/nz1XMTZCai2Op7clT386e3l9vFBb2eYKOexx8udRqDbmwDqkR10els3i-RYeH7ukSSoGWtSDp8A=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/nz1XMTZCai2Op7clT386e3l9vFBb2eYKOexx8udRqDbmwDqkR10els3i-RYeH7ukSSoGWtSDp8A=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/nz1XMTZCai2Op7clT386e3l9vFBb2eYKOexx8udRqDbmwDqkR10els3i-RYeH7ukSSoGWtSDp8A=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "Bitcoin verstehen",
"liveBroadcastContent": "none",
"publishTime": "2020-05-24T15:48:35Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "j2amjttw_gCECoVnlJEB4Y5g41E",
"id": {
"kind": "youtube#channel",
"channelId": "UC61jC9ggxeGu8HJ9Q_TxOGg"
},
"snippet": {
"publishedAt": "2013-09-06T02:12:33Z",
"channelId": "UC61jC9ggxeGu8HJ9Q_TxOGg",
"title": "BITCOIN",
"description": "YouTube.com/c/BITC0IN https://Odysee.com/#BITCOIN:d77 https://Twitter.com/BITC0INALLCAPS https://zbd.gg/BITC0IN - Tip ...",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/WG8_95AszbGpSw8w2Qx1VWq_1Ko6-VIvfezMG_YRi330HpZMWQaroK1wMf--zBXKddg4TW2Wvg=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/WG8_95AszbGpSw8w2Qx1VWq_1Ko6-VIvfezMG_YRi330HpZMWQaroK1wMf--zBXKddg4TW2Wvg=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/WG8_95AszbGpSw8w2Qx1VWq_1Ko6-VIvfezMG_YRi330HpZMWQaroK1wMf--zBXKddg4TW2Wvg=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "BITCOIN",
"liveBroadcastContent": "upcoming",
"publishTime": "2013-09-06T02:12:33Z"
}
},
[...]
]
}

Get Youtube Video URL using Youtube V3 API & JavaScript

I have searched alot on this topic but i was only able to find resources related to V2 of Youtube API which is nor depricated.
What i want to do is get Youtube video title, thumbnail and link from the JSON response of the Youtube V3 API URL using Javascript.
I run the code below but get an error message Uncaught TypeError: Cannot read property 'items' of undefined
<input id="searchquery" />
<div id="results"></div>
<!-- Include the latest jQuery library -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$('#searchquery').keyup(function () {
// the search term
var q = $('#searchquery').val().trim();
// container to display search results
var $results = $('#results');
// YouTube Data API base URL (JSON response)
var url = "https://www.googleapis.com/youtube/v3/search?part=snippet&order=date&key=AIzaSyC3TJRI1C0EVEdl7b19InH1gv9yrAOX2YU"
url = url + '&max-results=50';
$.getJSON(url + "&q=" + q, function (json) {
var count = 0;
if (json.data.items) {
var items = json.data.items;
var html = "";
items.forEach(function (item) {
// Check the duration of the video,
// full-length movies are generally longer than 1 hour
var duration = Math.round((item.duration) / (60 * 60));
// Filter out videos that aren't in the Film or Movies category
if ((duration > 1) && (item.category == "Movies" || item.category == "Film")) {
// Include the YouTube Watch URL youtu.be
html += '<p><a href="http://youtu.be/' + item.id + '">';
// Add the default video thumbnail (default quality)
html += '<img src="http://i.ytimg.com/vi/' + item.id + '/default.jpg">';
// Add the video title and the duration
html += '<h2>' + item.title + ' ' + item.duration + '</h2></a></p>';
count++;
}
});
}
// Did YouTube return any search results?
if (count === 0) {
$results.html("No videos found");
} else {
// Display the YouTube search results
$results.html(html);
}
});
});
});
</script>
My url is
https://www.googleapis.com/youtube/v3/search?part=snippet&order=date&key=AIzaSyC3TJRI1C0EVEdl7b19InH1gv9yrAOX2YU&q=opencourseware
this returns
{
"kind": "youtube#searchListResponse",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/anQeVHiFN6CH_dx-tP89Q8heOos\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 24815,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/4DMiUQkDt0Bic4cV0lZbi7KZ1tk\"",
"id": {
"kind": "youtube#playlist",
"playlistId": "PL-4XVpiAbrw8bRUhUHfm-omUYAyBepYiB"
},
"snippet": {
"publishedAt": "2015-09-01T06:23:39.000Z",
"channelId": "UCOY4GuDhH3KHVcpZqD5S87w",
"title": "Popular Videos - Bioinformatics & OpenCourseWare",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/R-PjAS8d1_0/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/R-PjAS8d1_0/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/R-PjAS8d1_0/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/-D3XCQyB-podnhbL-keBQoIZMb8\"",
"id": {
"kind": "youtube#video",
"videoId": "vOpp8nOp9uA"
},
"snippet": {
"publishedAt": "2015-08-10T09:27:38.000Z",
"channelId": "UCBL-6EKd9b1DW73ZcY-PNcw",
"title": "Audio OpenCourseWare",
"description": "OpenCourseWare dilaksanakan pada tanggal 10 Juli 2015 di Ruang Video Conference, Gedung D, Lantai 2 Direktorat Sistem Informasi, Telkom University ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/vOpp8nOp9uA/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/vOpp8nOp9uA/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/vOpp8nOp9uA/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/hwBjyzzUi0M3qf0QKR6EvAD6RTs\"",
"id": {
"kind": "youtube#playlist",
"playlistId": "PL2Co6UkQCJCrvFuM-KEY6Pfccm2PKNhGe"
},
"snippet": {
"publishedAt": "2015-08-03T21:28:26.000Z",
"channelId": "UCqHlUWMIi07M5U6kVSJT7RA",
"title": "Popular Videos - OpenCourseWare & Teacher",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/SQI2I48QUBQ/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/SQI2I48QUBQ/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/SQI2I48QUBQ/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/igp-ZANLFmAQxfuTsPHpNeJwdwg\"",
"id": {
"kind": "youtube#playlist",
"playlistId": "PLfu3FYNDydnC8bAZrkXpFXXxbCE8O9ZYS"
},
"snippet": {
"publishedAt": "2015-07-07T15:38:00.000Z",
"channelId": "UCqL4K9FRJ90uHEvRsSXi5cA",
"title": "Popular Videos - MIT OpenCourseWare & Field",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/PgE9oBDIgdc/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/PgE9oBDIgdc/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/PgE9oBDIgdc/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/9G1cGWzCiMxuc7L_KpgWTyJFjzk\"",
"id": {
"kind": "youtube#playlist",
"playlistId": "PL2Co6UkQCJCp_IpNmpim5CPhKC0gE95jv"
},
"snippet": {
"publishedAt": "2015-06-19T21:28:19.000Z",
"channelId": "UCqHlUWMIi07M5U6kVSJT7RA",
"title": "Popular Videos - OpenCourseWare & Educational Technology",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/ad4oFCHBSRQ/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/ad4oFCHBSRQ/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/ad4oFCHBSRQ/hqdefault.jpg"
}
},
"channelTitle": "",
"liveBroadcastContent": "none"
}
}
]
}
Change json.data.items to json.items

trying to bind a JSON object to a dropdownlist

Good afternoon SO,
I have a dropdownbox called: "#dropDownDest" I'm trying to bind
a JSON object to this dropdown "dropdowndest" but have been unable to do so.
Would you please direct me on what exactly am I doing wrong?
$('#dropDownDest').html('<pre>' + JSON.stringify(JSONOBJECT) + '</pre>');
This is a sample of the return JSON element:
{
"kind": "youtube#searchListResponse",
"etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/x2_4Du3jO25OnFY9_O_B3xXrQC0\"",
"nextPageToken": "CAUQAA",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/M-VYdHEsqyE1SqT3g91C7VdEHj0\"",
"id": {
"kind": "youtube#video",
"videoId": "Vi8VKaOi2nc"
},
"snippet": {
"publishedAt": "2014-05-09T16:12:09.000Z",
"channelId": "UClsy9JcwIVaq29WhPFI0eBg",
"title": "BEST FUNNY DOGS COMPILATION LONG (2013 - 2014)",
"description": "BEST FUNNY DOGS COMPILATION (2013 - 2014) Funny Animals includes cats, dogs, elephants, goats, otters, seals, birds, monkeys, Funny Cats, Funny, Dogs, ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Vi8VKaOi2nc/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/Vi8VKaOi2nc/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/Vi8VKaOi2nc/hqdefault.jpg"
}
},
"channelTitle": "onehourcompilations",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/YEKnjRQqLp8j1qKJDy8sxNW3wKY\"",
"id": {
"kind": "youtube#video",
"videoId": "D_eo7PZy4Dc"
},
"snippet": {
"publishedAt": "2015-05-12T17:00:01.000Z",
"channelId": "UC5GSO2hiHevgZUhSQIJNd2A",
"title": "SLEEPING DOGS - RENDIAMOCI UTILI",
"description": "A 5€ qui: http://bit.ly/ScontiGiochi Sitorna a menare le mani su Sleeping Dogs, dopo GTA 5 mi è tornata voglia di andare in Cina a picchiare un po' di sgherri.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/D_eo7PZy4Dc/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/D_eo7PZy4Dc/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/D_eo7PZy4Dc/hqdefault.jpg"
}
},
"channelTitle": "QueiDueSulServer2",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/5M32hctZeuP9PvX7ZBoiAx5oVeM\"",
"id": {
"kind": "youtube#video",
"videoId": "CpbYBZKdi3s"
},
"snippet": {
"publishedAt": "2014-05-10T21:37:35.000Z",
"channelId": "UCKy3MG7_If9KlVuvw3rPMfw",
"title": "Cute dogs waking up owners - Funny dog compilation",
"description": "Awesome Halloween costumes for babies, children and adults: For babies: Puppy costume: ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/CpbYBZKdi3s/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/CpbYBZKdi3s/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/CpbYBZKdi3s/hqdefault.jpg"
}
},
"channelTitle": "wloltigerlolw2",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/0SjgjtKwO10wRaYuKHIJ15B6i1s\"",
"id": {
"kind": "youtube#video",
"videoId": "fk9iJougDFE"
},
"snippet": {
"publishedAt": "2014-07-23T19:09:29.000Z",
"channelId": "UCsKQLakuQKvr4LG4VLOpWDQ",
"title": "10 MINUTES OF FUNNY DOGS",
"description": "SUBSCRIBE & BECOME A FOLLOWER OF FUNNY: http://www.youtube.com/subscription_center?add_user=tuneintoaccess NEW VIDEOS MONDAY, ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/fk9iJougDFE/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/fk9iJougDFE/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/fk9iJougDFE/hqdefault.jpg"
}
},
"channelTitle": "tuneintoaccess",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"tbWC5XrSXxe1WOAx6MK9z4hHSU8/o0Zb5d1-RECh4OCIVJgkLnvP9BA\"",
"id": {
"kind": "youtube#video",
"videoId": "RKBcs9tNWg8"
},
"snippet": {
"publishedAt": "2013-08-16T03:09:51.000Z",
"channelId": "UCVUdHi-tdW5AKdzMiTPG97Q",
"title": "Dogs Welcoming Soldiers Home Compilation 2012 [HD]",
"description": "Soldiers coming home to their lovable pups Dogs Welcome Home Soldiers 2014 - https://www.youtube.com/watch?v=5BnxV9H_ExA Puppies & Babies & Kitties ...",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/RKBcs9tNWg8/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/RKBcs9tNWg8/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/RKBcs9tNWg8/hqdefault.jpg"
}
},
"channelTitle": "funnyplox",
"liveBroadcastContent": "none"
}
}
]
}
See http://jsfiddle.net/qxn7sry3/1/
You need to select some value for the option value and the text. You can iterate through the array in the object and append them to the select as <option ...
for (var i = 0; i < JSONOBJECT.items.length; i++) {
var item = JSONOBJECT.items[i];
$("#dropDownDest").append('<option value=' + item.id.videoId + '>' + item.snippet.title + '</option>');
}

Passing function argument to retrieve data from an object

I am have some trouble with a script I am working on. I have been provided with an object with multiple items from a product catalog.
What I am trying to do is to write a function which to which will allow me to render this data easily.
<script type="application/javascript">
SKUinfo =
{
"s238554": {
"Age": {
"Description": "Age 18+",
"Thumbnail": "/productImages/assets/img/icon18.gif"
},
"Barcode": {
"Barcode": "50622132430794"
},
"Currency": "£",
"Description": "Description goes here",
"Id": 44305,
"Packshots": [
"/productImages/238556/1min.jpg",
"/productImages/238556/2med.jpg",
"/productImages/238556/3max.jpg"
],
"Pegis": [],
"Platform": {
"Button": "Xbox 360",
"ID": 0
},
"Publisher": {
"Description": null
},
"Release": "/Date(1392940800000+0000)/",
"Screenshots": [
{
"ScreenshotMax": "/productImages/238556/5scrmax1.jpg",
"ScreenshotMin": "/productImages/238556/4scrmin1.jpg"
}
],
"Title": "Product title 2 goes here",
"Variants": [
{
"Id": 58242,
"MaxOrderQuantity": 3,
"Presellable": true,
"Price": 29.97,
"PriceCultureFormat": "29.97",
"PriceWithCurrencyFormat": "£29.97",
"Sku": 238556,
"Type": {
"Description": "New"
}
},
],
"Vendor": {
"Description": ""
},
},
"s238556": {
"Age": {
"Description": "Age 18+",
"Thumbnail": "/productImages/assets/img/pegi/icon18.gif"
},
"Barcode": {
"Barcode": "5060134530794"
},
"Currency": "£",
"Description": "Description here",
"Id": 654654,
"Packshots": [
"/productImages/238556/1min.jpg",
"/productImages/238556/2med.jpg",
"/productImages/238556/3max.jpg"
],
"Pegis": [],
"Platform": {
"Button": "PlayStation 3",
"ID": 0
},
"Publisher": {
"Description": null
},
"Release": "/Date(1392940800000+0000)/",
"Screenshots": [
{
"ScreenshotMax": "/productImages/238556/5scrmax1.jpg",
"ScreenshotMin": "/productImages/238556/4scrmin1.jpg"
},
{
"ScreenshotMax": "/productImages/238556/7scrmax2.jpg",
"ScreenshotMin": "/productImages/238556/6scrmin2.jpg"
},
],
"Title": "Product title 2 goes here",
"Variants": [
{
"Id": 58242,
"MaxOrderQuantity": 3,
"Presellable": true,
"Price": 29.97,
"PriceCultureFormat": "29.97",
"PriceWithCurrencyFormat": "£29.97",
"Sku": 238556,
"Type": {
"Description": "New"
}
},
],
"Vendor": {
"Description": ""
},
"VideoHTML": "html here",
"status": {
"Response": "product found",
"Success": true
}
}
}
</script>
The above example is the output I get for two products.
If I try to get access to this data this is where I have a problem
<script type="application/javascript">
function getSKU(s)
{
console.log(SKUinfo.s.Title);
}
getSKU(s238554);
</script>
I imagine this is being caused when I am passing the argument s back to the function getSKU a the node selection in the data object. In this I would expect the console output to be the Title from SKU s238554.
What I get however, is: Uncaught ReferenceError: s238554 is not defined
I would appreciate any guidance that can be offered as I am a javascript novice.
Access your property by used[] on SKUinfo.s.Title like SKUinfo[s].Title
And also pass your property name within the quotes 's238554' as it's not variable.
Something like this.
function getSKU(s){
console.log(SKUinfo[s].Title);
}
getSKU('s238554'); // s238554 within quotes.

Facebook Open Graph not returning all results for Books.Read?

When using the Facebook Open Graph explorer, I run the following, to get a list of my books read.
/706685881/books.reads?limit=25&offset=0
This returns only 5 results, even though I have more books read than that, and I've explicitly requested up to 25 results. Following the paging link to the (theoretical) more results, shows a page with no more results.
here's my output of the query:
{
"data": [
{
"data": {
"book": {
"id": "452418224806835",
"url": "https://www.facebook.com/pages/Fantastic-Voyage/452418224806835",
"type": "books.book",
"title": "Fantastic Voyage"
}
},
"id": "10151871872740882"
},
{
"data": {
"book": {
"id": "106151566083577",
"url": "https://www.facebook.com/pages/The-Andromeda-Strain/106151566083577",
"type": "books.book",
"title": "The Andromeda Strain"
}
},
"id": "10151870390740882"
},
{
"data": {
"progress": [
{
"timestamp": 1388668020,
"percent_complete": 0
},
{
"timestamp": 1392949225,
"percent_complete": 100
}
],
"book": {
"id": "10150233066083545",
"url": "http://www.goodreads.com/book/show/10664113-a-dance-with-dragons",
"type": "good_reads:book",
"title": "A Dance with Dragons (A Song of Ice and Fire, #5)"
}
},
"id": "10151867499170882"
},
{
"data": {
"progress": [
{
"timestamp": 1391350736,
"percent_complete": 0
},
{
"timestamp": 1392569208,
"percent_complete": 100
}
],
"book": {
"id": "1390736374489290",
"url": "http://www.goodreads.com/book/show/18405477-city-of-the-sun",
"type": "good_reads:book",
"title": "City of the Sun"
}
},
"id": "10151860185710882"
},
{
"data": {
"book": {
"id": "526531387368738",
"url": "http://apps.facebook.com/bookscout/?currworkid=9000000000133742",
"type": "books.book",
"title": "Gates of Fire"
}
},
"id": "10151226827780882"
}
],
"paging": {
"next": "https://graph.facebook.com/706685881/books.reads?fields=data&limit=25&offset=25&__after_id=10151226827780882"
}
}
Anybody seeing what I am doing wrong?

Categories

Resources