【发布时间】:2014-11-12 13:25:31
【问题描述】:
在我的应用程序中,用户通过 google+ 凭据登录,我已为其实现了用于身份验证/授权的 google+ 框架。成功登录后,我必须获取登录用户的联系人列表。
我使用 Google Contacts API 3.0 版 url https://www.google.com/m8/feeds/contacts/default/full
GPP 登录身份验证请求后..
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error) {
NSLog(@"%@",[NSString stringWithFormat:@"Status: Authentication error: %@", error]);
return;
}
auth.clientID =@"XXXX.apps.googleusercontent.com";
auth.clientSecret =@"xxxxxxxx-z7tmOqQCShgH3ax";
NSString *urlStr = @"https://www.google.com/m8/feeds/contacts/default/full";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"3.0" forHTTPHeaderField:@"GData-Version"];
auth.scope= @"https://www.googleapis.com/auth/contacts.readonly";
[auth authorizeRequest:request
completionHandler:^(NSError *error) {
NSString *output = nil;
if (error) {
output = [error description];
} else {
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (data) {
// API fetch succeeded :Here I am getti
output = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(@"%@", output);
} else {
// fetch failed
output = [error description];
}
}
}];
}
在成功的响应中我写了这样的代码。
但输出不如预期。 输出字符串是巨大的垃圾值,并在它的末尾显示
401. 这是一个错误。
有一个 您的请求中有错误。这就是我们的全部 知道。
谁能帮忙解决这个问题。
【问题讨论】:
-
你好@CKT 你还有工作吗?我也陷入了这种情况。请帮我。谢谢。
标签: ios objective-c google-plus google-oauth google-contacts-api