Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-19-2011, 10:36 AM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 5
MZimmerman6 is on a distinguished road
Default Accessing Event Information GData API

I am trying access event information from an already filled out google calendar so that I can display this information in a custom layout. I want to be able to access the title as well as information such as time and date of the event, and whatever else I may need.

I currently have the GData stuff in the application, but I am not able to get the data from the calendar. Can anyone lend a hand? Thanks in advance!
MZimmerman6 is offline   Reply With Quote
Old 05-19-2011, 04:03 PM   #2 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

This should help:

Code:
#pragma mark -
#pragma mark Google Calendar API

- (GDataServiceGoogleCalendar *)calendarService {
	
	static GDataServiceGoogleCalendar* service = nil;
	
	if (!service) {
		service = [[GDataServiceGoogleCalendar alloc] init];
		
		[service setShouldCacheDatedData:YES];
		[service setServiceShouldFollowNextLinks:YES];
	}
	
	[service setUserCredentialsWithUsername:GOOGLE_ACCOUNT_USERNAME
								   password:GOOGLE_ACCOUNT_PASSWORD];
	
	return service;
}

#pragma mark -
#pragma mark Calendars

-(void)loadGoogleCalendarEvents{
	[self fetchAllCalendars];
}

- (void)fetchAllCalendars {
	
	GDataServiceGoogleCalendar *service = [self calendarService];
	GDataServiceTicket *ticket;
	
	ticket = [service fetchFeedWithURL:[NSURL URLWithString:kGDataGoogleCalendarDefaultOwnCalendarsFeed]
							  delegate:self
					 didFinishSelector:@selector(calendarListTicket:finishedWithFeed:error:)];
}

// fetch calendar metafeed callback
- (void)calendarListTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedCalendar *)feed error:(NSError *)error {
	NSArray *calendars = [feed entries];
	if(calendars.count !=0){
		self.googleCalendar = [calendars objectAtIndex:0];
		[self fetchCalendarEvents];
	}
	else{
		NSLog(@"User has no calendars...");
	}
}

#pragma mark -
#pragma mark Events 

- (void)fetchCalendarEvents {
	if (self.googleCalendar) {
		// fetch the events feed
		NSURL *feedURL = [[self.googleCalendar alternateLink] URL];
		if (feedURL) {
			NSTimeInterval daysInTheFuture = GOOGLE_CALENDAR_DAY_AMOUNT * 86400;
			GDataDateTime *queryStartDate = [GDataDateTime dateTimeWithDate:[NSDate date] timeZone:[NSTimeZone defaultTimeZone]];
			GDataDateTime *queryEndDate = [GDataDateTime dateTimeWithDate:[[NSDate date] dateByAddingTimeInterval:daysInTheFuture] timeZone:[NSTimeZone defaultTimeZone]];
			
			GDataQueryCalendar *query = [GDataQueryCalendar calendarQueryWithFeedURL:feedURL];
			[query setMaxResults:100];
			[query setOrderBy:@"starttime"];
			[query setIsAscendingOrder:YES];
			[query setMinimumStartTime:queryStartDate];
			[query setMaximumStartTime:queryEndDate];
			
			GDataServiceGoogleCalendar *service = [self calendarService];
			GDataServiceTicket *ticket;
			ticket = [service fetchFeedWithQuery:query
										delegate:self
							   didFinishSelector:@selector(calendarEventsTicket:finishedWithFeed:error:)];
		}
	}
}

// event list fetch callback
- (void)calendarEventsTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedCalendarEvent *)feed error:(NSError *)error {
	self.calendarEvents = [feed entries];
	[calendarEventTable reloadData];
}
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 05-20-2011, 10:13 AM   #3 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 5
MZimmerman6 is on a distinguished road
Default

Quote:
Originally Posted by Bertrand21 View Post
This should help:

Code:
#pragma mark -
#pragma mark Google Calendar API

- (GDataServiceGoogleCalendar *)calendarService {
	
	static GDataServiceGoogleCalendar* service = nil;
	
	if (!service) {
		service = [[GDataServiceGoogleCalendar alloc] init];
		
		[service setShouldCacheDatedData:YES];
		[service setServiceShouldFollowNextLinks:YES];
	}
	
	[service setUserCredentialsWithUsername:GOOGLE_ACCOUNT_USERNAME
								   password:GOOGLE_ACCOUNT_PASSWORD];
	
	return service;
}

#pragma mark -
#pragma mark Calendars

-(void)loadGoogleCalendarEvents{
	[self fetchAllCalendars];
}

- (void)fetchAllCalendars {
	
	GDataServiceGoogleCalendar *service = [self calendarService];
	GDataServiceTicket *ticket;
	
	ticket = [service fetchFeedWithURL:[NSURL URLWithString:kGDataGoogleCalendarDefaultOwnCalendarsFeed]
							  delegate:self
					 didFinishSelector:@selector(calendarListTicket:finishedWithFeed:error:)];
}

// fetch calendar metafeed callback
- (void)calendarListTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedCalendar *)feed error:(NSError *)error {
	NSArray *calendars = [feed entries];
	if(calendars.count !=0){
		self.googleCalendar = [calendars objectAtIndex:0];
		[self fetchCalendarEvents];
	}
	else{
		NSLog(@"User has no calendars...");
	}
}

#pragma mark -
#pragma mark Events 

- (void)fetchCalendarEvents {
	if (self.googleCalendar) {
		// fetch the events feed
		NSURL *feedURL = [[self.googleCalendar alternateLink] URL];
		if (feedURL) {
			NSTimeInterval daysInTheFuture = GOOGLE_CALENDAR_DAY_AMOUNT * 86400;
			GDataDateTime *queryStartDate = [GDataDateTime dateTimeWithDate:[NSDate date] timeZone:[NSTimeZone defaultTimeZone]];
			GDataDateTime *queryEndDate = [GDataDateTime dateTimeWithDate:[[NSDate date] dateByAddingTimeInterval:daysInTheFuture] timeZone:[NSTimeZone defaultTimeZone]];
			
			GDataQueryCalendar *query = [GDataQueryCalendar calendarQueryWithFeedURL:feedURL];
			[query setMaxResults:100];
			[query setOrderBy:@"starttime"];
			[query setIsAscendingOrder:YES];
			[query setMinimumStartTime:queryStartDate];
			[query setMaximumStartTime:queryEndDate];
			
			GDataServiceGoogleCalendar *service = [self calendarService];
			GDataServiceTicket *ticket;
			ticket = [service fetchFeedWithQuery:query
										delegate:self
							   didFinishSelector:@selector(calendarEventsTicket:finishedWithFeed:error:)];
		}
	}
}

// event list fetch callback
- (void)calendarEventsTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedCalendarEvent *)feed error:(NSError *)error {
	self.calendarEvents = [feed entries];
	[calendarEventTable reloadData];
}
I will give this a try, hopefully I can get it to work, thanks so much for your help in advance if it does work
MZimmerman6 is offline   Reply With Quote
Old 05-20-2011, 10:41 AM   #4 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by MZimmerman6 View Post
I will give this a try, hopefully I can get it to work, thanks so much for your help in advance if it does work
It does work. I've used it in my project.
__________________
Haters gonna Hate
Likers gonna Like
Bertrand21 is offline   Reply With Quote
Old 05-20-2011, 11:04 AM   #5 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 5
MZimmerman6 is on a distinguished road
Default

Quote:
Originally Posted by Bertrand21 View Post
It does work. I've used it in my project.
I completely trusted you, but I meant work for my purposes. Thanks a lot for your help I got it working.

However, will this method work as well for linked calendars from other people. An example being if a person added a calendar from another user to their own calendar. How would I go about accessing that?

Last edited by MZimmerman6; 05-20-2011 at 11:07 AM.
MZimmerman6 is offline   Reply With Quote
Old 05-20-2011, 11:09 AM   #6 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 5
MZimmerman6 is on a distinguished road
Default

Quote:
Originally Posted by MZimmerman6 View Post
I completely trusted you, but I meant work for my purposes. Thanks a lot for your help I got it working.

However, will this method work as well for linked calendars from other people. An example being if a person added a calendar from another user to their own calendar. How would I go about accessing that?
Nevermind, in order to do this you would edit the URLWithString argument in fetch all calendars to kGDataGoogleCalendarDefaultAllCalendarsFeed, and then later you can change the array index, in calendarListTicket, to access a specific calendar, as long as the calendar remains in the same place.
MZimmerman6 is offline   Reply With Quote
Old 08-12-2011, 02:46 AM   #7 (permalink)
Registered Member
 
Join Date: Aug 2011
Location: Pakistan
Posts: 12
mhk_mubashir is on a distinguished road
Default

Quote:
Originally Posted by Bertrand21 View Post
This should help:

Code:
#pragma mark -
#pragma mark Google Calendar API

- (GDataServiceGoogleCalendar *)calendarService {
	
	static GDataServiceGoogleCalendar* service = nil;
	
	if (!service) {
		service = [[GDataServiceGoogleCalendar alloc] init];
		
		[service setShouldCacheDatedData:YES];
		[service setServiceShouldFollowNextLinks:YES];
	}
	
	[service setUserCredentialsWithUsername:GOOGLE_ACCOUNT_USERNAME
								   password:GOOGLE_ACCOUNT_PASSWORD];
	
	return service;
}

#pragma mark -
#pragma mark Calendars

-(void)loadGoogleCalendarEvents{
	[self fetchAllCalendars];
}

- (void)fetchAllCalendars {
	
	GDataServiceGoogleCalendar *service = [self calendarService];
	GDataServiceTicket *ticket;
	
	ticket = [service fetchFeedWithURL:[NSURL URLWithString:kGDataGoogleCalendarDefaultOwnCalendarsFeed]
							  delegate:self
					 didFinishSelector:@selector(calendarListTicket:finishedWithFeed:error:)];
}

// fetch calendar metafeed callback
- (void)calendarListTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedCalendar *)feed error:(NSError *)error {
	NSArray *calendars = [feed entries];
	if(calendars.count !=0){
		self.googleCalendar = [calendars objectAtIndex:0];
		[self fetchCalendarEvents];
	}
	else{
		NSLog(@"User has no calendars...");
	}
}

#pragma mark -
#pragma mark Events 

- (void)fetchCalendarEvents {
	if (self.googleCalendar) {
		// fetch the events feed
		NSURL *feedURL = [[self.googleCalendar alternateLink] URL];
		if (feedURL) {
			NSTimeInterval daysInTheFuture = GOOGLE_CALENDAR_DAY_AMOUNT * 86400;
			GDataDateTime *queryStartDate = [GDataDateTime dateTimeWithDate:[NSDate date] timeZone:[NSTimeZone defaultTimeZone]];
			GDataDateTime *queryEndDate = [GDataDateTime dateTimeWithDate:[[NSDate date] dateByAddingTimeInterval:daysInTheFuture] timeZone:[NSTimeZone defaultTimeZone]];
			
			GDataQueryCalendar *query = [GDataQueryCalendar calendarQueryWithFeedURL:feedURL];
			[query setMaxResults:100];
			[query setOrderBy:@"starttime"];
			[query setIsAscendingOrder:YES];
			[query setMinimumStartTime:queryStartDate];
			[query setMaximumStartTime:queryEndDate];
			
			GDataServiceGoogleCalendar *service = [self calendarService];
			GDataServiceTicket *ticket;
			ticket = [service fetchFeedWithQuery:query
										delegate:self
							   didFinishSelector:@selector(calendarEventsTicket:finishedWithFeed:error:)];
		}
	}
}

// event list fetch callback
- (void)calendarEventsTicket:(GDataServiceTicket *)ticket finishedWithFeed:(GDataFeedCalendarEvent *)feed error:(NSError *)error {
	self.calendarEvents = [feed entries];
	[calendarEventTable reloadData];
}
Hi Bertrand21 i needed a little help to im using GData api 1.7.0 with GettingStarted - iphone-gcal - Setting up the XCode project for your development environment - An Objective-C project that uses Google Data APIs to access Google Calendar contents on your iPhone - Google Project Hosting this Google Calendar project in xcode 4.2 i have resolved all the errors and warnings but the issue is that when the application launches the Google calendar is stuck at the "Please wait" screen i did a lot of postings on the others forums but still no response i hope that any one can help there
mhk_mubashir is offline   Reply With Quote
Reply

Bookmarks

Tags
calendar, gdata, xml

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 358
7 members and 351 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, PlutoPrime, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0