所以我已经向youtube数据api发送了一个请求,它像一个魅力一样工作,绝对没有问题。我复制并粘贴了相同的文本,然后修改为我认为是令人满意的分析请求,但是当我对这个请求的结果进行NSLog时,没有记录任何内容。有人知道这是怎么回事吗?我以为这意味着请求没有成功。下面是我的代码:
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);
如果有人能给我指出一个工作的分析请求示例的方向,我会非常感激,因为我似乎不能把一个从api谷歌文档。
Thanks in advance
sendSynchronousRequest:returningResponse:error:
返回NSData
,而不是您代码中的NSURLConnection
。改为:
NSData *data = [NSURLConnection sendSynchronousRequest:analyticsRequest
returningResponse:&response
error:&error];
NSString *analyticsResponseString = [[NSString alloc]initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(@"%@", analyticsResponseString);