I am trying to create an application that will retrieve Google Calendar information such as calendars, events, etc., but I ran into a big problem.
This is my code:
#define GoogleClientID @"client id"
#define GoogleClientSecret @"secret"
#define GoogleAuthURL @"https://accounts.google.com/o/oauth2/auth"
#define GoogleTokenURL @"https://accounts.google.com/o/oauth2/token"
NSString *const kKeychainItemName = @"Calendar Panel: Google Calendar";
- (instancetype)initWithViewController: (UIViewController*) viewController;
{
self = [super init];
if (self) {
_viewController = viewController;
}
return self;
}
- (BOOL)isSignedIn {
NSString *name = [self signedInUsername];
return (name != nil);
}
- (NSString *)signedInUsername {
GTMOAuth2Authentication *auth = self.calendarService.authorizer;
BOOL isSignedIn = auth.canAuthorize;
if (isSignedIn) {
return auth.userEmail;
} else {
return nil;
}
}
- (GTMOAuth2Authentication * )authForGoogle
{
NSURL * tokenURL = [NSURL URLWithString:GoogleTokenURL];
NSString * redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication * auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"lifebeat"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:GoogleClientID
clientSecret:GoogleClientSecret];
auth.scope = @"https://www.googleapis.com/auth/userinfo.profile";
return auth;
}
- (void)signInToGoogle
{
if (![self isSignedIn]) {
GTMOAuth2Authentication * auth = [self authForGoogle];
GTMOAuth2ViewControllerTouch * viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth
authorizationURL:[NSURL URLWithString:GoogleAuthURL]
keychainItemName:@"GoogleKeychainName"
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[[self.viewController navigationController] pushViewController:viewController animated:YES];
} else
NSLog(@"Something wrong with the sign in procedure!");
}
- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController
finishedWithAuth:(GTMOAuth2Authentication * )auth
error:(NSError * )error
{
NSLog(@"finished");
NSLog(@"auth access token: %@", auth.accessToken);
self.calendarService.authorizer = auth;
[[self.viewController navigationController] popToViewController:self.viewController animated:NO];
if (error != nil) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error Authorizing with Google"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
} else {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Success Authorizing with Google"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
- (void)fetchCalendarList {
self.calendarList = nil;
self.calendarListFetchError = nil;
GTLServiceCalendar *service = self.calendarService;
GTLQueryCalendar *query = [GTLQueryCalendar queryForCalendarListList];
self.calendarListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
id calendarList, NSError *error) {
self.calendarList = calendarList;
self.calendarListFetchError = error;
self.calendarListTicket = nil;
NSLog(@"Fetched number of calendars: %@", self.calendarList);
}];
}
- (GTLServiceCalendar *)calendarService {
static GTLServiceCalendar *service = nil;
if (!service) {
service = [[GTLServiceCalendar alloc] init];
service.shouldFetchNextPages = YES;
service.retryEnabled = YES;
}
return service;
}
@end
This is the console output:
2014-09-10 23:57:53.603 CalendarPanel[24383:60b] GTLDriveChannel (api#channel) registration conflicts with GTLCalendarChannel
2014-09-10 23:57:53.607 CalendarPanel[24383:60b] GTLPlusDomainsAcl (plus#acl) registration conflicts with GTLPlusAcl
2014-09-10 23:57:53.607 CalendarPanel[24383:60b] GTLPlusDomainsActivity (plus#activity) registration conflicts with GTLPlusActivity
2014-09-10 23:57:53.608 CalendarPanel[24383:60b] GTLPlusDomainsActivityFeed (plus#activityFeed) registration conflicts with GTLPlusActivityFeed
2014-09-10 23:57:53.608 CalendarPanel[24383:60b] GTLPlusDomainsComment (plus#comment) registration conflicts with GTLPlusComment
2014-09-10 23:57:53.609 CalendarPanel[24383:60b] GTLPlusDomainsCommentFeed (plus#commentFeed) registration conflicts with GTLPlusCommentFeed
2014-09-10 23:57:53.609 CalendarPanel[24383:60b] GTLPlusPeopleFeed (plus#peopleFeed) registration conflicts with GTLPlusDomainsPeopleFeed
2014-09-10 23:57:53.610 CalendarPanel[24383:60b] GTLPlusPerson (plus#person) registration conflicts with GTLPlusDomainsPerson
2014-09-10 23:57:53.610 CalendarPanel[24383:60b] GTLPlusPlace (plus#place) registration conflicts with GTLPlusDomainsPlace
2014-09-10 23:57:53.613 CalendarPanel[24383:60b] GTLStorageChannel (api#channel) registration conflicts with GTLDriveChannel
2014-09-10 23:57:53.986 CalendarPanel[24383:60b] Fetched number of calendars: (null)
My two questions: 1. How can I get rid of these conflicts? 2. Does my code look fine for what I want to do? (fetching all calendars from the user) I think that using these GData classes is really difficult and there is very limited or very outdated information there.
source
share