das Zugriffstoken Um eine authorise Anfrage an den Google-API, damit Sie die folgenden Methoden implementieren sollten:
- (GTMOAuth2ViewControllerTouch *)createAuthController {
GTMOAuth2ViewControllerTouch *authController;
// If modifying these scopes, delete your previously saved credentials by
// resetting the iOS simulator or uninstall the app.
NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeGmailReadonly, nil];
authController = [[GTMOAuth2ViewControllerTouch alloc]
initWithScope:[scopes componentsJoinedByString:@" "]
clientID:kClientID
clientSecret:nil
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
return authController;
}
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)authResult
error:(NSError *)error {
if (error != nil) {
...
}
else {
NSLog(@"Access token: %@", authResult.accessToken);
}
}
Und Ihre ViewDidAppear Methode sollte wie folgt aussieht:
- (void)viewDidAppear:(BOOL)animated {
if (!self.service.authorizer.canAuthorize) {
// Not yet authorized, request authorization by pushing the login UI onto the UI stack.
[self presentViewController:[self createAuthController] animated:YES completion:nil];
}
Dieser Code gibt das Zielzugriffstoken aus.
Nach dem Beispiel habe ich Google-Anmeldung für Benutzer, aber nach der Autorisierungsanfrage noch 'https://www.googleapis.com/gmail/v1/users/me/labels/UNREAD?key= {MY_API_KEY}' gibt mir ein Fehler: Anfrage fehlgeschlagen: nicht autorisiert (401) – ArtStyle