Youtube分析示例请求iOS

时间:2014-03-25 21:46:16

标签: ios google-analytics youtube-api

所以我已经向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 google docs放在一起。

提前致谢

1 个答案:

答案 0 :(得分:1)

sendSynchronousRequest:returningResponse:error:会返回NSData,而不是代码中的NSURLConnection。将其更改为:

NSData *data = [NSURLConnection sendSynchronousRequest:analyticsRequest
                                     returningResponse:&response 
                                                 error:&error];

NSString *analyticsResponseString = [[NSString alloc]initWithData:data 
                                                         encoding:NSUTF8StringEncoding];
NSLog(@"%@", analyticsResponseString);