As I saw in your other post (Google API - Invalid Credentials) you know how to make an authenticated Alamofire
request. Now you need to build a proper parameters dictionary to meet the API requirements. I looked into the Youtube Data API guide.
This is the example of a JSON body provided in the documentation for adding a comment:
{
"snippet": {
"channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"topLevelComment": {
"snippet": {
"textOriginal": "This video is awesome!"
}
},
"videoId": "MILSirUni5E"
}
}
Let's build a parameters dictionary based on the above example, it is a nested dictionary:
let commentParams: Parameters = ["textOriginal": "This video is awesome!"]
let snippetParams: Parameters = ["snippet": commentParams]
let topLevelSnippet: Parameters = [
"channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"topLevelComment": snippetParams,
"videoId": "MILSirUni5E"]
let allParams: Parameters = ["snippet": topLevelSnippet]
Then create your headers, your request and pass the parameters to the request
let headers: HTTPHeaders = ["Authorization": "Bearer \(token)"]
// As API requires "part" is added as url parameter
let path = "https://www.googleapis.com/youtube/v3/commentThreads?part=snippet"
let request = Alamofire.request(path, method: HTTPMethod.post, parameters: allParams, encoding: JSONEncoding.default, headers: headers)
You should check which parameters are mandatory and which ones are not, but the idea is to build a proper parameters dictionary based on their requirements.
GTLRYouTubeQuery_CommentsInsert
. See: github.com/google/google-api-objectivec-client-for-rest/blob/… – Gibeon