Thanks for providing all these details! Although, next time I suggest having your two lower comments as the original post. You can always edit the original post if you forgot something later.
It looks like you forgot to add the parameter in your AF.request
. Perhaps, add it there, and it will fix things:
AF.request(url,
parameters: ["part": "snippet", "maxResults": "49","playlistId":Constants.PLAYLIST_ID,"key":Constants.API_KEY]
Otherwise, another way to call the API, would be to build your URL
with URLComponents
. This is how you would likely call it:
var urlComponents = URLComponents(string: Constants.apiUrl)
// Add the query parameters
urlComponents?.queryItems = [
URLQueryItem(name: "part", value: "snippet"),
URLQueryItem(name: "maxResults", value: "49"),
URLQueryItem(name: "playlistId", value: String(Constants.PLAYLIST_ID)),
URLQueryItem(name: "key", value: Constants.API_KEY)
]
let url = urlComponents?.url
// If the url is not nil, then proceed
if let url = url {
// Call YouTube API here
}
That’s a little cleaner way to build this long URL string. From there, you can print(url)
to see if it generates the response you want. You can see an example of how I call an API using the same method here starting at line 111: City-Sights-App/ContentModel.swift at master · agholson/City-Sights-App · GitHub
If that still doesn’t work, then I would suggest firing up Proxyman. This proxies your requests, so you can see all of the network requests made by your app. See here for details on how to use it: GitHub - agholson/City-Sights-App
Hope this gets you moving in the right direction!
Cheers,
Andrew