繁体   English   中英

Google Contacts API 3.0版是否可以检索目标C(iOS)示例请求格式的所有联系人?

[英]Google Contacts API version 3.0 to retrieve all contacts for objective C (iOS) sample request format?

在我的应用程序中,用户通过google +凭据登录,我已为其实施google +框架进行身份验证/授权。 成功登录后,我必须获取已登录用户的联系人列表。

我正在使用的Google Contacts API版本3.0网址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.那是一个错误。

您的请求中有一个错误。 我们知道的就这些。

任何人都可以帮助解决该问题。

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

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

如何使用NSURLConnection与SSL连接以获得不受信任的证书?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM