Wie kann ich Google Mail-Kontakte in einer iOS-Anwendung mit Google Contacts API abrufen?
In meiner Bewerbung haben wir die Möglichkeit behalten, uns über Google Mail anzumelden. Ich muss Google Mail-Kontakte abrufen.
In der folgenden Methode verwende ich Auth-Objekt (einmal Erfolg), um Google Mail-Kontakte durch Erstellen einer Anfrage mit URL abzurufen: "https: //www.google.com/m8/feeds/contacts/default/ful"
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if(!error) {
auth.clientID =myClientId;
auth.clientSecret =myClientSecret;
auth.scope= @"https://www.googleapis.com/auth/contacts.readonly";
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 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];
}
}
}];
}
}
Ich erhalte einen Clientfehler (401). Gibt es etwas, das mir bei meiner Anfrage fehlt?