Related
I have made a program where users provide a YouTube channel URL and in return I will show the user its channel ID.
Like if someone puts URL like: https://youtube.com/#AndreoBee then I will return its channel ID.
const axios = require('axios');
async function getChannelId(url) {
const channelUsername = url.split('/').pop();
const response = await axios.get(`https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=${channelUsername}&key=myapi`);
if (response.data.items.length === 0) {
throw new Error(`Channel not found: ${url}`);
}
console.log(response.data.items[0].id);
}
getChannelId('https://www.youtube.com/#AndreoBee');
Output:
/home/runner/ytcheck/index.js:7 if (response.data.items.length ===
0) {
^
TypeError: Cannot read properties of undefined (reading 'length')
at getChannelId (/home/runner/ytcheck/index.js:7:27)
One alternative - using YouTube Data API - could be:
Use the search:list endpoint for search channels that matches with the criteria - in this case, the name/handle of the channel.
Example:
Search channels named "AndreoBee" - you're getting this value in the channelUsername variable in your code:
URL:
https://youtube.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=10&q=AndreoBee&type=channel&key=[YOUR_API_KEY]
Response:
{
"kind": "youtube#searchListResponse",
"etag": "K2G-sXJIFnrJFyMaoDvw4XMBym4",
"nextPageToken": "CAoQAA",
"regionCode": "CO",
"pageInfo": {
"totalResults": 6740,
"resultsPerPage": 10
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "oeyNublAqxB8TOEQbtwA4k0Oqgs",
"id": {
"kind": "youtube#channel",
"channelId": "UCjdjyjdcdmldCK5XuuWbn1A"
},
"snippet": {
"publishedAt": "2020-01-21T15:12:27Z",
"channelId": "UCjdjyjdcdmldCK5XuuWbn1A",
"title": "AndreoBee",
"description": "I am a Youtuber.",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJW_gCXDGAviuBWh0GwUO4V5Ia4JNYzC0Mp9bYhigA=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJW_gCXDGAviuBWh0GwUO4V5Ia4JNYzC0Mp9bYhigA=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJW_gCXDGAviuBWh0GwUO4V5Ia4JNYzC0Mp9bYhigA=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBee",
"liveBroadcastContent": "none",
"publishTime": "2020-01-21T15:12:27Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "iG8-NwZab0LLB245AY2MkJ6pexI",
"id": {
"kind": "youtube#channel",
"channelId": "UC2Xpzteb9hbamaeEHZRxPCw"
},
"snippet": {
"publishedAt": "2020-11-27T07:07:23Z",
"channelId": "UC2Xpzteb9hbamaeEHZRxPCw",
"title": "AndreoBee",
"description": "This is my backup channel guys ;)",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJVgMinAIKpEHBPjM2Os8fHFKcsxtTyTIflqTwVR=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJVgMinAIKpEHBPjM2Os8fHFKcsxtTyTIflqTwVR=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJVgMinAIKpEHBPjM2Os8fHFKcsxtTyTIflqTwVR=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBee",
"liveBroadcastContent": "none",
"publishTime": "2020-11-27T07:07:23Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "3X2zApHnPAW2p2awm4tIETn9ybI",
"id": {
"kind": "youtube#channel",
"channelId": "UCp6iawa7GPTszoJxOiG5d_Q"
},
"snippet": {
"publishedAt": "2021-03-15T16:19:39Z",
"channelId": "UCp6iawa7GPTszoJxOiG5d_Q",
"title": "AndreoBee",
"description": "Welcome my ARS GAMING YouTube channel I am uploading full movies or shorts and how to download movies on my YouTube ...",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/Z2CC1zWbsD3k-z9cX0RlPBstKELZw0_sUgFPggIt-DhVkJWL8iJG8pCLizxr3StB8lbZX9PT7U8=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/Z2CC1zWbsD3k-z9cX0RlPBstKELZw0_sUgFPggIt-DhVkJWL8iJG8pCLizxr3StB8lbZX9PT7U8=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/Z2CC1zWbsD3k-z9cX0RlPBstKELZw0_sUgFPggIt-DhVkJWL8iJG8pCLizxr3StB8lbZX9PT7U8=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBee",
"liveBroadcastContent": "none",
"publishTime": "2021-03-15T16:19:39Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "VHP4HsDcIiETPleAWN0cSC7fvbE",
"id": {
"kind": "youtube#channel",
"channelId": "UCWLY3sMMYHH3-9xQ2lhFj8g"
},
"snippet": {
"publishedAt": "2022-06-27T01:08:10Z",
"channelId": "UCWLY3sMMYHH3-9xQ2lhFj8g",
"title": "AndreoBee",
"description": "Hii guus i am Andreo I hope you like my videos and please support me guys thank you have a good day.",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/bHaKoA8QZnZSJXfmK7udtrzxmpCOOhpTHIoP_RQUD2KLv9qNXtLLKY_bewbaQGdfZGIPCcO9Ag=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/bHaKoA8QZnZSJXfmK7udtrzxmpCOOhpTHIoP_RQUD2KLv9qNXtLLKY_bewbaQGdfZGIPCcO9Ag=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/bHaKoA8QZnZSJXfmK7udtrzxmpCOOhpTHIoP_RQUD2KLv9qNXtLLKY_bewbaQGdfZGIPCcO9Ag=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBee",
"liveBroadcastContent": "none",
"publishTime": "2022-06-27T01:08:10Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "01NvBqsdnNimHwnwHnGkeVOhJ-8",
"id": {
"kind": "youtube#channel",
"channelId": "UC3yVv5tuR3tBcVf97j33mQQ"
},
"snippet": {
"publishedAt": "2020-12-12T14:31:22Z",
"channelId": "UC3yVv5tuR3tBcVf97j33mQQ",
"title": "Andreobee",
"description": "Describe the game All best game for play on Android in 2GB ram and 3GB phone.",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJXval25GhQFpbqoFgQXvWBol5aqf4ZCOluMMOe-=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJXval25GhQFpbqoFgQXvWBol5aqf4ZCOluMMOe-=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJXval25GhQFpbqoFgQXvWBol5aqf4ZCOluMMOe-=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "Andreobee",
"liveBroadcastContent": "none",
"publishTime": "2020-12-12T14:31:22Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "B5TOx4aFyuua9eQVa-QBbKDjIng",
"id": {
"kind": "youtube#channel",
"channelId": "UCBR0QlbTtbT52oFmmDZIamw"
},
"snippet": {
"publishedAt": "2022-02-01T14:44:18Z",
"channelId": "UCBR0QlbTtbT52oFmmDZIamw",
"title": "AndreoBee",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/TfGkwtvsAvJdWnMOdRLRn2HKRvnVj872dxLZdZ_ghFwpF4SrY2BqBwJ3syc1V6HLL3LyJiSABQ=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/TfGkwtvsAvJdWnMOdRLRn2HKRvnVj872dxLZdZ_ghFwpF4SrY2BqBwJ3syc1V6HLL3LyJiSABQ=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/TfGkwtvsAvJdWnMOdRLRn2HKRvnVj872dxLZdZ_ghFwpF4SrY2BqBwJ3syc1V6HLL3LyJiSABQ=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBee",
"liveBroadcastContent": "none",
"publishTime": "2022-02-01T14:44:18Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "t04J8v3aRhQhmFsyv54ddTXGDMQ",
"id": {
"kind": "youtube#channel",
"channelId": "UCBvdbv05Cb4Ulf_PlunMJtA"
},
"snippet": {
"publishedAt": "2021-08-12T06:59:40Z",
"channelId": "UCBvdbv05Cb4Ulf_PlunMJtA",
"title": "AndreoBee",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/S3J1R-s_P481lUpBULskSiQ0Pv-Z_iLnE_YrZ10OL1cydCFx6a1aOXvRJskMxY-gVpa8cqwuzQ=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/S3J1R-s_P481lUpBULskSiQ0Pv-Z_iLnE_YrZ10OL1cydCFx6a1aOXvRJskMxY-gVpa8cqwuzQ=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/S3J1R-s_P481lUpBULskSiQ0Pv-Z_iLnE_YrZ10OL1cydCFx6a1aOXvRJskMxY-gVpa8cqwuzQ=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBee",
"liveBroadcastContent": "none",
"publishTime": "2021-08-12T06:59:40Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "dmhfSWj6r1CzXr4yopXkorSsVL0",
"id": {
"kind": "youtube#channel",
"channelId": "UCvXV0HSenVdIpdAuogNPuOQ"
},
"snippet": {
"publishedAt": "2022-11-02T12:01:42Z",
"channelId": "UCvXV0HSenVdIpdAuogNPuOQ",
"title": "AndreoBee",
"description": "PLZ SUB.....",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/NfH1RxDcGEbLe8cOoi7VwFz-dfUcAToV-84rag4x1CIQM8GSnZirguR5SI30M3bZnMP80tA=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/NfH1RxDcGEbLe8cOoi7VwFz-dfUcAToV-84rag4x1CIQM8GSnZirguR5SI30M3bZnMP80tA=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/NfH1RxDcGEbLe8cOoi7VwFz-dfUcAToV-84rag4x1CIQM8GSnZirguR5SI30M3bZnMP80tA=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBee",
"liveBroadcastContent": "none",
"publishTime": "2022-11-02T12:01:42Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "c5Y3zUOZKiyJ-pI7mrLdi4WPegc",
"id": {
"kind": "youtube#channel",
"channelId": "UCmrR9PVxSVRLdp2HK_xP2yA"
},
"snippet": {
"publishedAt": "2021-09-13T06:16:47Z",
"channelId": "UCmrR9PVxSVRLdp2HK_xP2yA",
"title": "ANDREOBEE",
"description": "AndreoBee fan Club For business inquiries ANDREOBEEofficial.",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/CtsMEUKLJC5apm5bX7vEr_3g7nIJn-GfjLodWXLVLF-jFGfyXhFBTiLUvOU8l51e3kVPph5MUQ=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/CtsMEUKLJC5apm5bX7vEr_3g7nIJn-GfjLodWXLVLF-jFGfyXhFBTiLUvOU8l51e3kVPph5MUQ=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/CtsMEUKLJC5apm5bX7vEr_3g7nIJn-GfjLodWXLVLF-jFGfyXhFBTiLUvOU8l51e3kVPph5MUQ=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "ANDREOBEE",
"liveBroadcastContent": "none",
"publishTime": "2021-09-13T06:16:47Z"
}
},
{
"kind": "youtube#searchResult",
"etag": "-lb0jmjUJcQsLJDGHH7KVs14-nU",
"id": {
"kind": "youtube#channel",
"channelId": "UCvqm9nqHYYehmq7FcorjS4Q"
},
"snippet": {
"publishedAt": "2021-01-13T05:54:00Z",
"channelId": "UCvqm9nqHYYehmq7FcorjS4Q",
"title": "AndreoBEE",
"description": "",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJUIkodf8aTOx2ZcNoyycMHQqgqNvehuXN_iz9Ii=s88-c-k-c0xffffffff-no-rj-mo"
},
"medium": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJUIkodf8aTOx2ZcNoyycMHQqgqNvehuXN_iz9Ii=s240-c-k-c0xffffffff-no-rj-mo"
},
"high": {
"url": "https://yt3.ggpht.com/ytc/AL5GRJUIkodf8aTOx2ZcNoyycMHQqgqNvehuXN_iz9Ii=s800-c-k-c0xffffffff-no-rj-mo"
}
},
"channelTitle": "AndreoBEE",
"liveBroadcastContent": "none",
"publishTime": "2021-01-13T05:54:00Z"
}
}
]
}
N.B: for this case, I will accept that the first result is the channel I'm looking for, however, notice here that you might get more than one channel that matches the channel name.
For detect which one of the results of the search matches with the channel you're looking for, you could then, make a request to the channel:list endpoint - by passing the channel_id of the search result - and see their customUrl value and/or check the channel that has more videos/subscribers/etc.
Check my answer for more info.
You can get a channel id using /search Youtube API. Instead using this :
https://www.googleapis.com/youtube/v3/channels?part=id&forUsername=${channelUsername}&key=myapi
Try with this endpoint :
https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&q=${channelUsername}&type=channel&key=myapi
I'm getting a response from an API, I'm interested only in one of the link that returns. I have been using for a while
["data"]["tasks"]["0"]["result"]["files"]["0"]["url"]
to get the URL but it seems the API has changed and now the "result" it changes the position 0 in every call...
{"data": {
"id": "dcd99049-63b2",
"tag": "jobbuilder",
"status": "finished",
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:28+00:00",
"ended_at": "2022-11-22T21:57:33+00:00",
"tasks": [
{
"id": "48c34a03-54f2",
"name": "task-2",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 0,
"code": null,
"message": null,
"percent": 100,
"operation": "convert",
"engine": "qpdf",
"engine_version": "10.1.0",
"result": {
"files": [
{
"filename": "something.pdf",
"size": 633487
}
]
},
"created_at": "2022-11-22T21:57:30+00:00",
"started_at": "2022-11-22T21:57:32+00:00",
"ended_at": "2022-11-22T21:57:32+00:00",
"retry_of_task_id": null,
"copy_of_task_id": "dd64385a-a2e9",
"user_id": 6070,
"priority": 10,
"host_name": "meggie",
"storage": null,
"depends_on_task_ids": [
"dd64385a-a2e9",
"acfd2a2c-3c45"
],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/48c34a03-54f2"
}
},
{
"id": "6333e3b8-2f6f",
"name": "export-1",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 0,
"code": null,
"message": null,
"percent": 100,
"operation": "export/url",
"result": {
"files": [
{
"filename": "something.pdf",
"size": 633487,
"url": "https://storage.cloudconvert.com/tasks/somethinglink.pdf"
}
]
},
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:32+00:00",
"ended_at": "2022-11-22T21:57:32+00:00",
"retry_of_task_id": null,
"copy_of_task_id": null,
"user_id": 607,
"priority": 10,
"host_name": "meggie",
"storage": "ceph-fra",
"depends_on_task_ids": [
"48c34a03-54f2"
],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/6333e3b8-2f6f"
}
},
{
"id": "dd64385a-a2e9",
"name": "task-2-create-watermark",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 1,
"code": null,
"message": null,
"percent": 100,
"operation": "watermark",
"engine": "imagemagick",
"engine_version": "7.1.0",
"result": {
"files": [
{
"filename": "watermark.pdf",
"size": 609229
}
]
},
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:30+00:00",
"ended_at": "2022-11-22T21:57:32+00:00",
"retry_of_task_id": null,
"copy_of_task_id": null,
"user_id": 6070,
"priority": 10,
"host_name": "meggie",
"storage": "ceph-fra",
"depends_on_task_ids": [
"acfd2a2c-3c45-4e47"
],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/dd64385a-a2e9"
}
},
{
"id": "acfd2a2c-3c45-4e47",
"name": "task-1",
"job_id": "dcd99049-63b2",
"status": "finished",
"credits": 1,
"code": null,
"message": null,
"percent": 100,
"operation": "capture-website",
"engine": "wkhtml",
"engine_version": "0.12.5",
"result": {
"files": [
{
"filename": "something.pdf",
"size": 27330
}
]
},
"created_at": "2022-11-22T21:57:28+00:00",
"started_at": "2022-11-22T21:57:28+00:00",
"ended_at": "2022-11-22T21:57:30+00:00",
"retry_of_task_id": null,
"copy_of_task_id": null,
"user_id": 6070,
"priority": 10,
"host_name": "meggie",
"storage": null,
"depends_on_task_ids": [],
"links": {
"self": "https://api.cloudconvert.com/v2/tasks/acfd2a2c-3c45"
}
}
],
"links": {
"self": "https://api.cloudconvert.com/v2/jobs/dcd99049-63b2-443e"
}
}};
I would like to always extract only the link:
https://storage.cloudconvert.com/tasks/somethinglink.pdf
which position can change as mentioned before... The link always start with https://storage.cloudconvert.com
I have been using this for a while to access the first object in the array
["data"]["tasks"]["0"]["result"]["files"]["0"]["url"]
but it doesn't seem to work if the link it's in a different position...
This code extracts all values as strings, then finds the one with the necessary prefix:
const data = {"data":{"id":"dcd99049-63b2","tag":"jobbuilder","status":"finished","created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:28+00:00","ended_at":"2022-11-22T21:57:33+00:00","tasks":[{"id":"48c34a03-54f2","name":"task-2","job_id":"dcd99049-63b2","status":"finished","credits":0,"code":null,"message":null,"percent":100,"operation":"convert","engine":"qpdf","engine_version":"10.1.0","result":{"files":[{"filename":"something.pdf","size":633487}]},"created_at":"2022-11-22T21:57:30+00:00","started_at":"2022-11-22T21:57:32+00:00","ended_at":"2022-11-22T21:57:32+00:00","retry_of_task_id":null,"copy_of_task_id":"dd64385a-a2e9","user_id":6070,"priority":10,"host_name":"meggie","storage":null,"depends_on_task_ids":["dd64385a-a2e9","acfd2a2c-3c45"],"links":{"self":"https://api.cloudconvert.com/v2/tasks/48c34a03-54f2"}},{"id":"6333e3b8-2f6f","name":"export-1","job_id":"dcd99049-63b2","status":"finished","credits":0,"code":null,"message":null,"percent":100,"operation":"export/url","result":{"files":[{"filename":"something.pdf","size":633487,"url":"https://storage.cloudconvert.com/tasks/somethinglink.pdf"}]},"created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:32+00:00","ended_at":"2022-11-22T21:57:32+00:00","retry_of_task_id":null,"copy_of_task_id":null,"user_id":607,"priority":10,"host_name":"meggie","storage":"ceph-fra","depends_on_task_ids":["48c34a03-54f2"],"links":{"self":"https://api.cloudconvert.com/v2/tasks/6333e3b8-2f6f"}},{"id":"dd64385a-a2e9","name":"task-2-create-watermark","job_id":"dcd99049-63b2","status":"finished","credits":1,"code":null,"message":null,"percent":100,"operation":"watermark","engine":"imagemagick","engine_version":"7.1.0","result":{"files":[{"filename":"watermark.pdf","size":609229}]},"created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:30+00:00","ended_at":"2022-11-22T21:57:32+00:00","retry_of_task_id":null,"copy_of_task_id":null,"user_id":6070,"priority":10,"host_name":"meggie","storage":"ceph-fra","depends_on_task_ids":["acfd2a2c-3c45-4e47"],"links":{"self":"https://api.cloudconvert.com/v2/tasks/dd64385a-a2e9"}},{"id":"acfd2a2c-3c45-4e47","name":"task-1","job_id":"dcd99049-63b2","status":"finished","credits":1,"code":null,"message":null,"percent":100,"operation":"capture-website","engine":"wkhtml","engine_version":"0.12.5","result":{"files":[{"filename":"something.pdf","size":27330}]},"created_at":"2022-11-22T21:57:28+00:00","started_at":"2022-11-22T21:57:28+00:00","ended_at":"2022-11-22T21:57:30+00:00","retry_of_task_id":null,"copy_of_task_id":null,"user_id":6070,"priority":10,"host_name":"meggie","storage":null,"depends_on_task_ids":[],"links":{"self":"https://api.cloudconvert.com/v2/tasks/acfd2a2c-3c45"}}],"links":{"self":"https://api.cloudconvert.com/v2/jobs/dcd99049-63b2-443e"}}}
const f=i=>i instanceof Object?Object.values(i).flatMap(v=>f(v)):[i+'']
console.log(f(data).find(i=>
i.startsWith('https://storage.cloudconvert.com/tasks/')))
let parameters = {
"lifespanCount": 3,
"parameters": {
"fields": {
"date.original": {
"stringValue": "tomorrow",
"kind": "stringValue"
},
"duration.original": {
"stringValue": "3 days",
"kind": "stringValue"
},
"date": {
"structValue": {
"fields": {
"sys.date.recent.original": {
"stringValue": "tomorrow",
"kind": "stringValue"
},
"sys.date.original": {
"stringValue": "tomorrow",
"kind": "stringValue"
},
"sys.date": {
"stringValue": "2018-12-11T12:00:00-05:00",
"kind": "stringValue"
},
"sys.date.recent": {
"stringValue": "2018-12-11T12:00:00-05:00",
"kind": "stringValue"
},
"sys.date.partial": {
"stringValue": "2018-12-11T12:00:00-05:00",
"kind": "stringValue"
},
"sys.date.partial.original": {
"stringValue": "tomorrow",
"kind": "stringValue"
}
}
},
"kind": "structValue"
},
"yes.original": {
"stringValue": "",
"kind": "stringValue"
},
"duration": {
"structValue": {
"fields": {
"sys.duration.object": {
"structValue": {
"fields": {}
},
"kind": "structValue"
},
"sys.duration": {
"structValue": {
"fields": {
"unit": {
"stringValue": "day",
"kind": "stringValue"
},
"amount": {
"numberValue": 3,
"kind": "numberValue"
}
}
},
"kind": "structValue"
},
"sys.duration.original": {
"stringValue": "3 days",
"kind": "stringValue"
}
}
},
"kind": "structValue"
},
"location.original": {
"stringValue": "china",
"kind": "stringValue"
},
"location": {
"structValue": {
"fields": {
"sys.geo-country.original": {
"stringValue": "china",
"kind": "stringValue"
},
"sys.geo-country.object": {
"structValue": {
"fields": {}
},
"kind": "structValue"
},
"sys.geo-country": {
"stringValue": "China",
"kind": "stringValue"
}
}
},
"kind": "structValue"
}
}
}
}
From above object what is the best way to get values like,
let date = parameters.fields['date'].structValue.fields['sys.date'].stringValue;
let country = parameters.fields['location'].structValue.fields['sys.geo-country'].stringValue
what can be a common function so, anyone can access value directly if pass object and key
i have tried object.values(), object.keys() have also read MDN docs but not getting much more regarding this. what my aim is to get the value from object when i pass any key with object.
Based purely on your two examples, the easiest way seems to be:
function getString(paramField, structField) {
if (parameters.fields[paramField] && parameters.fields[paramField].structValue.fields[structField]) {
return parameters.fields[paramField].structValue.fields[structField].stringValue;
}
return '';
}
Maybe some additional checks are in order, depending on the likelihood of other variance to the structure.
Then the calling code can just be:
let date = getString('date', 'sys.date');
The response of "GET https://www.googleapis.com/youtube/v3/playlistItems" for a Playlist contains deleted video will return missing item in the array, Checked the errors page however nothing seems to be returning an error in such a case.
Playlistid: PLn0Hg2TufJCmcAxBFzk8z28M7bph-TV2L
Deleted Videoid: _cXqnTRHpZU
response:
/**
* API response
*/
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/T8BMpwombSYE5-LT4FpqCHDEwUQ\"",
"pageInfo": {
"totalResults": 10,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/4rqnSq9-GjuC3jGefwsyaa5CBvg\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC41MjE1MkI0OTQ2QzJGNzNG",
"contentDetails": {
"videoId": "ob6ISU-f1ho",
"videoPublishedAt": "2011-05-01T16:25:52.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/RFwjMeMjCTaRZUDphrJCA7UUBkE\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC41MzJCQjBCNDIyRkJDN0VD",
"contentDetails": {
"videoId": "CGRf2Mpj8Yc",
"videoPublishedAt": "2009-09-27T07:59:37.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/iUGZwVKJfLxCV-8Bo2riBnbGl_c\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC5DQUNERDQ2NkIzRUQxNTY1",
"contentDetails": {
"videoId": "hEhYol0gEg4",
"videoPublishedAt": "2014-03-28T17:44:11.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/u_C1CEJaTi1zTsOIkXif0D5q1b8\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC45NDk1REZENzhEMzU5MDQz",
"contentDetails": {
"videoId": "wqv6r02ndLo",
"videoPublishedAt": "2013-10-02T10:23:13.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/PMFK40fcEeXgwuNE3gdtDX4rE5M\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC5GNjNDRDREMDQxOThCMDQ2",
"contentDetails": {
"videoId": "eRr6TibE9G0",
"videoPublishedAt": "2014-05-14T11:59:06.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/uYJMJTAtsEIisl_vothDzAtUmXc\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC40NzZCMERDMjVEN0RFRThB",
"contentDetails": {
"videoId": "JISlUIUY3sA",
"videoPublishedAt": "2013-05-07T17:57:02.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/fnfbDo29xDX_41j7WwAHlOWCRXs\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC5EMEEwRUY5M0RDRTU3NDJC",
"contentDetails": {
"videoId": "rvXbj0jh2lA",
"videoPublishedAt": "2014-05-28T17:55:37.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/MtvoZWwjFDcxXIlop7Nwu0hgnhI\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC45ODRDNTg0QjA4NkFBNkQy",
"contentDetails": {
"videoId": "ExEP-ZhT3sQ",
"videoPublishedAt": "2013-11-08T17:51:22.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/VP-V_aDLbLQO7lHFj7TsZBDYj1U\"",
"id": "UExuMEhnMlR1ZkpDbWNBeEJGems4ejI4TTdicGgtVFYyTC4zMDg5MkQ5MEVDMEM1NTg2",
"contentDetails": {
"videoId": "lWkhXQJMPCQ",
"videoPublishedAt": "2013-01-21T21:28:51.000Z"
}
}
]
}
In my case the "totalResults": 10, however the array is returning 9 items. According to my testing the only way to generate the error
GET https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails%2Cstatus&maxResults=50&playlistId=PLn0Hg2TufJCmcAxBFzk8z28M7bph-TV2L&videoId=_cXqnTRHpZU&key={YOUR_API_KEY}
Response:
404
- Show headers -
{
"error": {
"errors": [
{
"domain": "youtube.playlistItem",
"reason": "videoNotFound",
"message": "Video not found.",
"locationType": "parameter",
"location": "videoId"
}
],
"code": 404,
"message": "Video not found."
}
}
The purpose behind this is to detect these deleted video in a specific playlist and then to delete it.
First off, I'm very new to working with APIs at all. And English is not my first language. I've searched the web but came up short in finding exactly what I'm looking for, or at least I have not understood enough of what I read to understand how to alter and apply it to my situation.
I'm working with the Omdb API and the Giphy API, making a silly page. I'm using JavaScript and HTML.
At the end I want the page to display the search result of the user searching for a movie + on-topic gifs.
I've come so far that I have a result from both APIs. That's all good and well. What I don't know how to do is to from these results present, for example, just the movie titles and the .gif-files. My attempts at splitting the returned results have so far failed. Any suggestions? Below is my JavaScript code.
var form = document.getElementById('search-form');
form.addEventListener("submit", search);
function search(event) {
event.preventDefault();
document.getElementById("present_result").innerHTML = "";
if(this.elements.query.value === '') {
alert("Enter search word!");
} else {
var rawInputData = this.elements.query.value;
var fixedInputData = rawInputData.split(" ");
var inputData = encodeQueryData(fixedInputData);
var inputDataGif = encodeQueryDataGif(fixedInputData);
function encodeQueryData(data) {
let ret = [];
for (let d in data)
ret.push(encodeURIComponent(data[d]));
return ret.join('%20');
}
function encodeQueryDataGif(data) {
let ret = [];
for (let d in data)
ret.push(encodeURIComponent(data[d]));
return ret.join('+');
}
var omdbAPI = new XMLHttpRequest();
var gifAPI = new XMLHttpRequest();
var omdbURL = "http://www.omdbapi.com/?s=" + inputData + "&type=movie";
var gifURL = "http://api.giphy.com/v1/gifs/search?q=" + inputDataGif + "&limit=1&api_key=dc6zaTOxFJmzC";
omdbAPI.addEventListener("load", function() {
if (this.responseText === '{"Response":"False","Error":"Movie not found!"}')
{
alert("No result.");
} else {
var result = JSON.parse(this.responseText);
console.log(result);
result = JSON.stringify(result);
document.getElementById("present_result").innerHTML = result;
}
});
gifAPI.addEventListener("load", function() {
if (this.responseText === '{"Response":"False","Error":"Not found!"}')
{
alert("No Result.");
} else {
var result = JSON.parse(this.responseText);
console.log(result);
result = JSON.stringify(result);
document.getElementById("present_gif").innerHTML = result;
}
});
omdbAPI.open("get", omdbURL, true);
omdbAPI.send();
gifAPI.open("get", gifURL, true);
gifAPI.send();
}
}
And below the HTML.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Mashup test</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<!-- Form -->
<form action="" method="get" id="search-form" class="search-form">
Movie: <input type="text" name="query">
<button type="submit" id="submit">Search</button>
</form>
<!-- Result -->
<div id="present_result">
</div>
<div id="present_gif">
</div>
<script src="scripts.js"></script>
</body>
</html>
And here's a sample result from OMDb:
{
"Search": [{
"Title": "Titanic",
"Year": "1997",
"imdbID": "tt0120338",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BZDNiMjE0NDgtZWRhNC00YTlhLTk2ZjItZTQzNTU2NjAzNWNkXkEyXkFqcGdeQXVyNjUwNzk3NDc#._V1_SX300.jpg"
}, {
"Title": "Titanic II",
"Year": "2010",
"imdbID": "tt1640571",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTMxMjQ1MjA5Ml5BMl5BanBnXkFtZTcwNjIzNjg1Mw##._V1_SX300.jpg"
}, {
"Title": "Titanic: The Legend Goes On...",
"Year": "2000",
"imdbID": "tt0330994",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTg5MjcxODAwMV5BMl5BanBnXkFtZTcwMTk4OTMwMg##._V1_SX300.jpg"
}, {
"Title": "Titanic",
"Year": "1953",
"imdbID": "tt0046435",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTU3NTUyMTc3Nl5BMl5BanBnXkFtZTgwOTA2MDE3MTE#._V1_SX300.jpg"
}, {
"Title": "Raise the Titanic",
"Year": "1980",
"imdbID": "tt0081400",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTY5MTQwNzMxNV5BMl5BanBnXkFtZTcwMzkwOTMyMQ##._V1_SX300.jpg"
}, {
"Title": "The Legend of the Titanic",
"Year": "1999",
"imdbID": "tt1623780",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMjMxNDU5MTk1MV5BMl5BanBnXkFtZTgwMDk5NDUyMTE#._V1_SX300.jpg"
}, {
"Title": "The Chambermaid on the Titanic",
"Year": "1997",
"imdbID": "tt0129923",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMWUzYjgyNDEtNTAyMi00M2JjLTlhMzMtMDJmOGM1ZmYzNzY4XkEyXkFqcGdeQXVyMTA0MjU0Ng##._V1_SX300.jpg"
}, {
"Title": "In Search of the Titanic",
"Year": "2004",
"imdbID": "tt1719665",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTAzNjY0NDA2NzdeQTJeQWpwZ15BbWU4MDIwMzc1MzEx._V1_SX300.jpg"
}, {
"Title": "Titanic",
"Year": "1943",
"imdbID": "tt0036443",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTU2Njg4MDgxN15BMl5BanBnXkFtZTcwNzE4MjYyMQ##._V1_SX300.jpg"
}, {
"Title": "S.O.S. Titanic",
"Year": "1979",
"imdbID": "tt0079836",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTMwOTU5MDU0OV5BMl5BanBnXkFtZTcwMDc4OTYyMQ##._V1_SX300.jpg"
}],
"totalResults": "170",
"Response": "True"
}
And sample result from Giphy:
{
"data": [{
"type": "gif",
"id": "pWDH6fkHgGHza",
"slug": "titanic-leonardo-dicaprio-pWDH6fkHgGHza",
"url": "http://giphy.com/gifs/titanic-leonardo-dicaprio-pWDH6fkHgGHza",
"bitly_gif_url": "http://gph.is/Z15kA0",
"bitly_url": "http://gph.is/Z15kA0",
"embed_url": "http://giphy.com/embed/pWDH6fkHgGHza",
"username": "",
"source": "http://tomhiddles.tumblr.com/post/37231367662",
"rating": "g",
"content_url": "",
"source_tld": "tomhiddles.tumblr.com",
"source_post_url": "http://tomhiddles.tumblr.com/post/37231367662",
"is_indexable": 0,
"import_datetime": "2013-03-24 01:54:54",
"trending_datetime": "1970-01-01 00:00:00",
"images": {
"fixed_height": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/200.gif",
"width": "513",
"height": "200",
"size": "271598",
"mp4": "http://media0.giphy.com/media/pWDH6fkHgGHza/200.mp4",
"mp4_size": "19808",
"webp": "http://media0.giphy.com/media/pWDH6fkHgGHza/200.webp",
"webp_size": "392604"
},
"fixed_height_still": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/200_s.gif",
"width": "513",
"height": "200"
},
"fixed_height_downsampled": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/200_d.gif",
"width": "513",
"height": "200",
"size": "530508",
"webp": "http://media0.giphy.com/media/pWDH6fkHgGHza/200_d.webp",
"webp_size": "196204"
},
"fixed_width": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/200w.gif",
"width": "200",
"height": "78",
"size": "65057",
"mp4": "http://media0.giphy.com/media/pWDH6fkHgGHza/200w.mp4",
"mp4_size": "24950",
"webp": "http://media0.giphy.com/media/pWDH6fkHgGHza/200w.webp",
"webp_size": "74208"
},
"fixed_width_still": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/200w_s.gif",
"width": "200",
"height": "78"
},
"fixed_width_downsampled": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/200w_d.gif",
"width": "200",
"height": "78",
"size": "100970",
"webp": "http://media0.giphy.com/media/pWDH6fkHgGHza/200w_d.webp",
"webp_size": "37622"
},
"fixed_height_small": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/100.gif",
"width": "256",
"height": "100",
"size": "271598",
"mp4": "http://media0.giphy.com/media/pWDH6fkHgGHza/100.mp4",
"mp4_size": "170265",
"webp": "http://media0.giphy.com/media/pWDH6fkHgGHza/100.webp",
"webp_size": "98852"
},
"fixed_height_small_still": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/100_s.gif",
"width": "256",
"height": "100"
},
"fixed_width_small": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/100w.gif",
"width": "100",
"height": "39",
"size": "65057",
"mp4": "http://media0.giphy.com/media/pWDH6fkHgGHza/100w.mp4",
"mp4_size": "45670",
"webp": "http://media0.giphy.com/media/pWDH6fkHgGHza/100w.webp",
"webp_size": "23380"
},
"fixed_width_small_still": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/100w_s.gif",
"width": "100",
"height": "39"
},
"downsized": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy.gif",
"width": "500",
"height": "195",
"size": "1006467"
},
"downsized_still": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy_s.gif",
"width": "500",
"height": "195"
},
"downsized_large": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy.gif",
"width": "500",
"height": "195",
"size": "1006467"
},
"downsized_medium": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy.gif",
"width": "500",
"height": "195",
"size": "1006467"
},
"original": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy.gif",
"width": "500",
"height": "195",
"size": "1006467",
"frames": "12",
"mp4": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy.mp4",
"mp4_size": "84279",
"webp": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy.webp",
"webp_size": "378130"
},
"original_still": {
"url": "http://media0.giphy.com/media/pWDH6fkHgGHza/giphy_s.gif",
"width": "500",
"height": "195"
},
"looping": {
"mp4": "http://media.giphy.com/media/pWDH6fkHgGHza/giphy-loop.mp4"
},
"preview": {
"mp4": "http://media3.giphy.com/media/pWDH6fkHgGHza/giphy-preview.mp4",
"mp4_size": "44332",
"width": "326",
"height": "126"
},
"downsized_small": {
"mp4": "http://media3.giphy.com/media/pWDH6fkHgGHza/giphy-downsized-small.mp4",
"mp4_size": "116662"
}
}
}],
"meta": {
"status": 200,
"msg": "OK",
"response_id": "5887622069432538bfa2a521"
},
"pagination": {
"total_count": 11258,
"count": 1,
"offset": 0
}
}
Both APIs return you a JSON object.
A json object is generally construct like so:
{
"property1": "value1",
"property2": "value2"
"property_array": ["arrayValue1", "arrayValue2"],
"property_object": {
"propertyA": "valueA",
"attributeB": "valueB"
}
}
So let use OMDb (for example):
to access the results, you need to acces the "Search" attribute :
var entries = result.Search;
Then, you need to "loop" on each property of the Search object (whitch is also an object) :
to do so, you can use a for...in loop:
for(var entry_key in entries) {
// control that property is own by the object (not prototype)
if(entries.hasOwnProperty(entry_key)) {
// do whatever you want with the entry
// To access the entry, use this notation:
var entry = entries[entry_key];
// to stay with OMDb example, this should be:
var movie_title = entry.Title;
}
}
var results = {
"Search": [{
"Title": "Titanic",
"Year": "1997",
"imdbID": "tt0120338",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BZDNiMjE0NDgtZWRhNC00YTlhLTk2ZjItZTQzNTU2NjAzNWNkXkEyXkFqcGdeQXVyNjUwNzk3NDc#._V1_SX300.jpg"
}, {
"Title": "Titanic II",
"Year": "2010",
"imdbID": "tt1640571",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTMxMjQ1MjA5Ml5BMl5BanBnXkFtZTcwNjIzNjg1Mw##._V1_SX300.jpg"
}, {
"Title": "Titanic: The Legend Goes On...",
"Year": "2000",
"imdbID": "tt0330994",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTg5MjcxODAwMV5BMl5BanBnXkFtZTcwMTk4OTMwMg##._V1_SX300.jpg"
}, {
"Title": "Titanic",
"Year": "1953",
"imdbID": "tt0046435",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTU3NTUyMTc3Nl5BMl5BanBnXkFtZTgwOTA2MDE3MTE#._V1_SX300.jpg"
}, {
"Title": "Raise the Titanic",
"Year": "1980",
"imdbID": "tt0081400",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTY5MTQwNzMxNV5BMl5BanBnXkFtZTcwMzkwOTMyMQ##._V1_SX300.jpg"
}, {
"Title": "The Legend of the Titanic",
"Year": "1999",
"imdbID": "tt1623780",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMjMxNDU5MTk1MV5BMl5BanBnXkFtZTgwMDk5NDUyMTE#._V1_SX300.jpg"
}, {
"Title": "The Chambermaid on the Titanic",
"Year": "1997",
"imdbID": "tt0129923",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMWUzYjgyNDEtNTAyMi00M2JjLTlhMzMtMDJmOGM1ZmYzNzY4XkEyXkFqcGdeQXVyMTA0MjU0Ng##._V1_SX300.jpg"
}, {
"Title": "In Search of the Titanic",
"Year": "2004",
"imdbID": "tt1719665",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTAzNjY0NDA2NzdeQTJeQWpwZ15BbWU4MDIwMzc1MzEx._V1_SX300.jpg"
}, {
"Title": "Titanic",
"Year": "1943",
"imdbID": "tt0036443",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTU2Njg4MDgxN15BMl5BanBnXkFtZTcwNzE4MjYyMQ##._V1_SX300.jpg"
}, {
"Title": "S.O.S. Titanic",
"Year": "1979",
"imdbID": "tt0079836",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTMwOTU5MDU0OV5BMl5BanBnXkFtZTcwMDc4OTYyMQ##._V1_SX300.jpg"
}],
"totalResults": "170",
"Response": "True"
};
var movies_list = document.getElementById('movies-list');
var entries = results.Search;
for(var entry_key in entries) {
// control that property is own by the object (not prototype)
if(entries.hasOwnProperty(entry_key)) {
// do whatever you want with the entry
// To access the entry, use this notation:
var entry = entries[entry_key];
// to stay with OMDb example, this should be:
var movie_line = '<p><strong>Title:</strong> '
+ entry.Title + ' (year: ' + entry.Year + ')</p>';
movies_list.innerHTML += movie_line;
}
}
<div id="movies-list">
</div>