简体   繁体   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?

In my application user logs in throgh google+ credentials for which I have implemented google+ framework for authentication/authorization. 在我的应用程序中,用户通过google +凭据登录,我已为其实施google +框架进行身份验证/授权。 After Successful login I have to get the contacts list of the logged in user. 成功登录后,我必须获取已登录用户的联系人列表。

for which I am using Google Contacts API version 3.0 url https://www.google.com/m8/feeds/contacts/default/full 我正在使用的Google Contacts API版本3.0网址https://www.google.com/m8/feeds/contacts/default/full

After GPP Sign In authentication request.. 在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];
                 }
             }
         }];
}

in the successful response I have written code like this. 在成功的响应中,我编写了这样的代码。

But the output is not as desired. 但是输出不是期望的。 The output string is huge junk value and at the end of it is showing 输出字符串是巨大的垃圾值,并且在末尾显示

401. That's an error. 401.那是一个错误。

There was an error in your request. 您的请求中有一个错误。 That's all we know. 我们知道的就这些。

Could any one please help in resolving the issue. 任何人都可以帮助解决该问题。

401 means that you have not correctly authorized. 401表示您没有正确授权。 I don't work with that api but it's possible your credentials are incorrect. 我不使用该api,但您的凭据可能不正确。

you might also be seeing certificate problems for the https? 您可能还会看到https的证书问题? you should set up this call back and see if it provides more info. 您应该设置此回调,然后查看它是否提供更多信息。

How to use NSURLConnection to connect with SSL for an untrusted cert? 如何使用NSURLConnection与SSL连接以获得不受信任的证书?

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

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