我正在尝试使用OAuth2从Google云端硬盘下载,但我无法验证网址。
我收到以下错误:
2013-08-21 21:22:39.569 LoudCloud [4790:c07]授权 成功... 2013-08-21 21:22:40.262 LoudCloud [4790:c07]错误:错误 Domain = AFNetworkingErrorDomain Code = -1011“预期的状态代码 (200-299),获得401“UserInfo = 0x98b90f0 {AFNetworkingOperationFailingURLRequestErrorKey = HTTPS:?//doc-0k-bg-docs.googleusercontent.com/docs/securesc/6gj8c1544p7s7pniqjbc4mq6j0fb056i/8bj1nr5shkpsku5m0mde1rr8v7n975ll/1377108000000/00742820994415136760/00742820994415136760/0B0kZ8xc_ZGhbWnZOQUVuTGtObjA H = 16653014193614665626急症=下载&安培; GD =真&gt ;, NSErrorFailingURLKey = https://doc-0k-bg-docs.googleusercontent.com/docs/securesc/6gj8c1544p7s7pniqjbc4mq6j0fb056i/8bj1nr5shkpsku5m0mde1rr8v7n975ll/1377108000000/00742820994415136760/00742820994415136760/0B0kZ8xc_ZGhbWnZOQUVuTGtObjA?h=16653014193614665626&e=download&gd=true, NSLocalizedDescription =(200-299)中的预期状态代码,得到401, AFNetworkingOperationFailingURLResponseErrorKey =}
CODE:
GTMOAuth2Authentication *auth =
[GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
clientID:kClientID
clientSecret:kClientSecret];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[auth authorizeRequest:req completionHandler:^(NSError *error) {
if (error == nil) {
NSLog(@"Authorization successful...");
}
else {
NSLog(@"Authorization failed...");
}
}];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:req];
op.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[op setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
float percentage = ((float)((int)totalBytesRead) / (float)((int)totalBytesExpectedToRead)) * 100.0;
NSLog(@"Download percentage: %f", percentage);
}];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[op start];