gpt4 book ai didi

ios - youtube api 上的 EXC_BAD_INSTRUCTION

转载 作者:行者123 更新时间:2023-11-30 11:12:42 25 4
gpt4 key购买 nike

我从 YouTube 的 api 获取播放列表视频,如下所示:

这是视频类:

What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?

解析如下:

 let youtubeData = try JSONDecoder().decode(Video.self, from: data!)
for item in youtubeData.items{
print(item)
self.titles.append(item.snippet.title)
self.ids.append(item.contentDetails.videoID)
self.images.append((item.snippet.thumbnails.standard?.url)!)
}

链接是:

            let link: String = "https://www.googleapis.com/youtube/v3/playlistItems?key=AIzaSyCZD5QOrfmfKKeu2FbiTXzhEEr96Ky6tew&playlistId=PLbJRbIvdAVXRdkBSpA25hugmJy_rOKOYu&part=snippet,contentDetails&maxResults=20"

这就是 postman 所得到的:

    {
"kind": "youtube#playlistItemListResponse",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/rADsLSpprHJE-fPnym42pRX8eww\"",
"pageInfo": {
"totalResults": 4,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#playlistItem",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/6yrUGyNtxoJ1dmT3Y8sRBJLBeXE\"",
"id": "UExiSlJiSXZkQVZYUmRrQlNwQTI1aHVnbUp5X3JPS09ZdS41NkI0NEY2RDEwNTU3Q0M2",
"snippet": {
"publishedAt": "2018-08-17T02:56:10.000Z",
"channelId": "UCqXAWrjSgLb0EPa_icPt-pw",
"title": "Interview",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/CjNr5Gpa4TE/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/CjNr5Gpa4TE/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/CjNr5Gpa4TE/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/CjNr5Gpa4TE/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/CjNr5Gpa4TE/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "الدوري السعودي للمحترفين Saudi Pro League",
"playlistId": "PLbJRbIvdAVXRdkBSpA25hugmJy_rOKOYu",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "CjNr5Gpa4TE"
}
},
"contentDetails": {
"videoId": "CjNr5Gpa4TE",
"videoPublishedAt": "2018-07-28T19:04:42.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/9bldgOrkQOmEy3P6x_T4pJiqAss\"",
"id": "UExiSlJiSXZkQVZYUmRrQlNwQTI1aHVnbUp5X3JPS09ZdS4yODlGNEE0NkRGMEEzMEQy",
"snippet": {
"publishedAt": "2018-08-17T02:59:16.000Z",
"channelId": "UCqXAWrjSgLb0EPa_icPt-pw",
"title": "ورشة عمل مراقبي ومنسقي المباريات - اليوم الختامي",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/t-sLCUA68R0/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/t-sLCUA68R0/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/t-sLCUA68R0/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "الدوري السعودي للمحترفين Saudi Pro League",
"playlistId": "PLbJRbIvdAVXRdkBSpA25hugmJy_rOKOYu",
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "t-sLCUA68R0"
}
},
"contentDetails": {
"videoId": "t-sLCUA68R0",
"videoPublishedAt": "2018-07-28T17:01:42.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/Eue448TE2XiiTrzi8vuJICCFqwU\"",
"id": "UExiSlJiSXZkQVZYUmRrQlNwQTI1aHVnbUp5X3JPS09ZdS4wMTcyMDhGQUE4NTIzM0Y5",
"snippet": {
"publishedAt": "2018-08-17T02:59:24.000Z",
"channelId": "UCqXAWrjSgLb0EPa_icPt-pw",
"title": "ورشة عمل مراقبي ومنسقي المباريات - اليوم الأول",
"description": "ملخص اليوم الأول من ورشة عمل مراقبي ومنسقي المباريات والمنسقين الأمنيين والإعلاميين والتي تقيمها الرابطة بالتعاون مع الاتحاد السعودي والاتحاد الآسيوي لكرة القدم",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/tnUz7fLwEBM/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/tnUz7fLwEBM/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/tnUz7fLwEBM/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/tnUz7fLwEBM/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/tnUz7fLwEBM/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "الدوري السعودي للمحترفين Saudi Pro League",
"playlistId": "PLbJRbIvdAVXRdkBSpA25hugmJy_rOKOYu",
"position": 2,
"resourceId": {
"kind": "youtube#video",
"videoId": "tnUz7fLwEBM"
}
},
"contentDetails": {
"videoId": "tnUz7fLwEBM",
"videoPublishedAt": "2018-07-27T17:34:19.000Z"
}
},
{
"kind": "youtube#playlistItem",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/AjA_MynNqIpjpuSN8kJmW7zgDlk\"",
"id": "UExiSlJiSXZkQVZYUmRrQlNwQTI1aHVnbUp5X3JPS09ZdS41MjE1MkI0OTQ2QzJGNzNG",
"snippet": {
"publishedAt": "2018-08-17T02:59:33.000Z",
"channelId": "UCqXAWrjSgLb0EPa_icPt-pw",
"title": "حديث سلمان النمشان عن ورشة عمل مهام مراقبي ومنسقي المباريات والمنسقين الأمنيين والإعلاميين",
"description": "سلمان بن نمشان رئيس لجنة مراقبي ومنسقي المباريات في رابطة الدوري السعودي للمحترفين يتحدث عن أهمية ورشة عمل مراقبي ومنسقي المباريات والمنسقين الأمنيين والإعلاميين والتي تقيمها الرابطة بالتعاون مع الاتحاد السعودي والاتحاد الآسيوي لكرة القدم",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/wIIGgdEa9DU/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/wIIGgdEa9DU/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/wIIGgdEa9DU/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/wIIGgdEa9DU/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/wIIGgdEa9DU/maxresdefault.jpg",
"width": 1280,
"height": 720
}
},
"channelTitle": "الدوري السعودي للمحترفين Saudi Pro League",
"playlistId": "PLbJRbIvdAVXRdkBSpA25hugmJy_rOKOYu",
"position": 3,
"resourceId": {
"kind": "youtube#video",
"videoId": "wIIGgdEa9DU"
}
},
"contentDetails": {
"videoId": "wIIGgdEa9DU",
"videoPublishedAt": "2018-07-27T17:24:59.000Z"
}
}
]
}

但收到此错误:

Thread 2: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

在这一行中:

https://app.quicktype.io?share=aNLIT2lKl4ecggFJMRhY

当播放列表 ID 是这样时:

PLSmSEc8Z6liq82OteppRm-koytegaPX2C

..运行得很好!

有什么问题吗?以及如何解决这个问题?

最佳答案

在您的回复项目 ID 中

"kind": "youtube#playlistItem",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/9bldgOrkQOmEy3P6x_T4pJiqAss\""

没有缩略图>standrad->url路径值(没有standrad键)

关于ios - youtube api 上的 EXC_BAD_INSTRUCTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52025224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com