设备上的Ionic 404 HTTP请求

问题描述 投票:0回答:1

我有一个使用Youtube Data API的Ionic 3应用程序。我有一个GET请求从channeI ID返回播放列表。它在浏览器中工作正常但我从编译的应用程序和Android设备中获得404

getVideos(channel) {
   return this.http.get(`https://www.googleapis.com/youtube/v3/playlists?key=${this.apiKey}&channelId=${channel}&part=snippet,id&maxResults=20`)
              .map(res => {
                return res.json()['items'];
              })
  }

我也在我的config.xml中设置了API密钥。

 <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="YouTubeDataApiKey" value="XXXXXXXXXXX MY KEY XXXXXXXX" />

知道如何解决这个问题吗?

javascript angular cordova ionic-framework
1个回答
0
投票

传递给URL的params存在问题。

像这样构建你的字符串以添加参数值:

'https://www.googleapis.com/youtube/v3/playlists?key=' + ${this.apiKey} + '&channelId=' + ${channel} + '&part=snippet,id&maxResults=20'
© www.soinside.com 2019 - 2024. All rights reserved.