I am trying to upload a video to YouTube using the v3 API using AFNetworking 2.0. The download itself works fine, and I can see the video on my channel. I have a problem: parameters ( video resource ) to indicate the title, description, etc., which I should place as the request body (together with the video itself) Here is the code that I use.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"Bearer #_token_goes_here#" forHTTPHeaderField:@"Authorization"];
NSDictionary *parameters = @{@"snippet" : @{@"title" : @"random_title",
@"description" : @"random_description"}};
NSURL *filePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video" ofType:@"mov"]];
[manager POST:@"https://www.googleapis.com/upload/youtube/v3/videos?part=snippet,status" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileURL:filePath name:@"video" fileName:@"video.mov" mimeType:@"video/*" error:NULL];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
How to properly configure JSON parameters for a request? Thank.
source
share