Reputation: 194
So I've sent a request to the youtube data api and it works like a charm, absolutely no problem there. I copied and pasted the same text and then modified to what I believe to be a satisfactory analytics request, but when I NSLog the result of this request, nothing is logged. Does anyone know what is going on here? I thought it meant the request was unsuccessful. Here is my code:
NSMutableURLRequest *analyticsRequest = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"www.googleapis.com/youtube/analytics/v1/reports?ids=channel==%@&.end-date=2014-01-01&metrics=views&filters=video==%@", [userIDs objectAtIndex:k - 1], [array objectAtIndex:[array indexOfObject:@"videoId"] + 1]]]];
[GETRequest setHTTPMethod:@"GET"];
[GETRequest setValue:@"www.googleapis.com" forHTTPHeaderField:@"Host"];
[GETRequest setValue:[NSString stringWithFormat:@"Bearer %@", [self.defaults objectForKey:[NSString stringWithFormat:@"access_token %i", k]]] forHTTPHeaderField:@"Authorization"];
NSURLConnection *newConnection = [NSURLConnection sendSynchronousRequest:analyticsRequest returningResponse:&response error:&error];
NSString *analyticsResponseString = [[NSString alloc]initWithData:newConnection encoding:NSUTF8StringEncoding];
NSLog(@"%@", analyticsResponseString);
If anyone could point me in the direction of a working analytics request example I would be very grateful as I can't seem to put together one from the api google docs.
Thanks in advance
Upvotes: 1
Views: 72
Reputation: 40028
The sendSynchronousRequest:returningResponse:error:
returns NSData
, not NSURLConnection
as it is in your code. Change it to:
NSData *data = [NSURLConnection sendSynchronousRequest:analyticsRequest
returningResponse:&response
error:&error];
NSString *analyticsResponseString = [[NSString alloc]initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(@"%@", analyticsResponseString);
Upvotes: 1