【问题标题】:Google Contacts API version 3.0 to retrieve all contacts for objective C (iOS) sample request format?Google Contacts API 3.0 版检索目标 C (iOS) 示例请求格式的所有联系人?
【发布时间】: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


【解决方案1】:

401 表示您没有正确授权。我不使用该 API,但您的凭据可能不正确。

您可能还会看到 https 的证书问题?您应该设置此回调并查看它是否提供更多信息。

How to use NSURLConnection to connect with SSL for an untrusted cert?

【讨论】:

  • 凭据没有问题,如果我使用与 GData 相同的凭据,我就能获取联系人。我已经实现了您提供的链接中提到的 NSURLConnection SSL 证书委托方法。我发现证书也没有问题
猜你喜欢
  • 2014-08-15
  • 1970-01-01
  • 1970-01-01
  • 2017-02-11
  • 1970-01-01
  • 1970-01-01
  • 2015-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多