【发布时间】:2019-12-21 03:41:01
【问题描述】:
我看过很多关于这个问题的帖子,但我看到的只是嵌入的视频,我认为这不是我的情况。我有一个 URL,它应该根据用户的输入为我提供视频,以便可以观看预告片,但错误消息出现在控制台中:
拒绝在框架中显示“https://www.googleapis.com/youtube/v3/search?part=sn-p&q=robocop&topicId=%2Fm%2F02vxn&key=AIzaSyB42WhSTkS6_0uUPX6EuGakkGz4RHXnlIc”,因为它设置了“X-Frame-Options” ' 到 '同源'。
代码如下:
组件:
safeUrl: SafeResourceUrl
constructor(private movieService: MoviesService, private fb: FormBuilder,
private sanitizer: DomSanitizer) {}
ngOnInit() {
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl
("https://www.googleapis.com/youtube/v3/search?part=snippet&q=robocop&topicId=%2Fm%2F02vxn&key=AIzaSyB42WhSTkS6_0uUPX6EuGakkGz4RHXnlIc");
//this is a static URL to provide the robocop movie trailer
HTML:
<iframe [class.thumbnail]="thumbnail" [src]="safeUrl" width="560" height="315" frameborder="0" webkitallowfullscreen mozallowfullscreen
allowfullscreen></iframe>
我怎样才能做到这一点?将 URL 粘贴到浏览器上,我得到一个像这样的 json:
{
"kind": "youtube#searchListResponse",
"etag": "\"p4VTdlkQv3HQeTEaXgvLePAydmU/cDGghZKnwX2aAUA7AHR1yBLd91k\"",
"nextPageToken": "CAUQAA",
"regionCode": "PT",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"p4VTdlkQv3HQeTEaXgvLePAydmU/YWtWaXHndgHpHajPoRfWHslrqXc\"",
"id": {
"kind": "youtube#video",
"videoId": "Z931XZ2wfpE"
},
"snippet": {
"publishedAt": "2016-11-13T15:46:31.000Z",
"channelId": "UCuwxAIqBcP-9W9CNYAAg7KA",
"title": "RoboCop (1987) - First Mission (1080p) FULL HD",
"description": "For more RoboCop Videos - https://www.youtube.com/playlist?list=PLainponqoUGNp-P_Jg2359ahWVOJNdKpd.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/Z931XZ2wfpE/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/Z931XZ2wfpE/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/Z931XZ2wfpE/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "RED Lion Movie Shorts",
"liveBroadcastContent": "none"
}
},
【问题讨论】: