0
votes

How to use google calendar list insert with Objective-C.

https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert#response

I want add a public calendar[ID:[email protected]] to my calendar but there is some error

Error Domain=com.google.GTLJSONRPCErrorDomain Code=**403** "(Insufficient Permission)" UserInfo={error=Insufficient Permission, NSLocalizedFailureReason=(Insufficient Permission), GTLStructuredError=GTLErrorObject 0x7f9b40d0da00: {message:"Insufficient Permission" data:[1] code:403}}
2016-03-10 17:34:23.022 calendar20160225[10337:413037] error:(null)

I edit from https://developers.google.com/google-apps/calendar/quickstart/ios

I add this and got the error

-(void)myCalendarQuery
{

    NSString* enter code herenewCalendarName=@"[email protected]";
    GTLCalendarCalendarListEntry *entry=[GTLCalendarCalendar object];
    GTLServiceCalendar *service = self.service;

    GTLCalendarCalendar *newEntry = [GTLCalendarCalendar object];
    newEntry.summary = newCalendarName;
    newEntry.timeZone = [[NSTimeZone localTimeZone] name];

    GTLQueryCalendar *query = [GTLQueryCalendar queryForCalendarsInsertWithObject:newEntry];
    GTLServiceTicket* editCalendarListTicket =[[GTLServiceTicket alloc]init];



    [self.service executeQuery:query
                      delegate:self
             didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
    editCalendarListTicket = [service executeQuery:query
                                 completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
                                     // Callback
                                     //editCalendarListTicket = nil;
                                     if (error == nil) {

                                         [self fetchCalendarList];
                                     } else {
                                         NSLog(@"error:%@",error);
                                         [self fetchCalendarList];
                                         [self showAlert:@"Add failed" message:[NSString stringWithFormat:@"Calendar add failed: %@", error]];

                                     }

                                 }];


  //[email protected]
    GTLQueryCalendar *query2 = [GTLQueryCalendar queryForEventsListWithCalendarId:@"[email protected]"];

    [GTLQueryCalendar queryForEventsInsertWithObject:query calendarId:@"[email protected]"];
    query.maxResults = 10;
    query.timeMin = [GTLDateTime dateTimeWithDate:[NSDate date]
                                         timeZone:[NSTimeZone localTimeZone]];;
    query.singleEvents = YES;
    query.orderBy = kGTLCalendarOrderByStartTime;

    [self.service executeQuery:query
                      delegate:self
             didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
    //    [GTLQueryCalendar queryForAclInsertWithObject:query calendarId:@"[email protected]"];


}
2
You want to import all event from Google Calendar?kb920
I just want to add but I only can get the list .Jay Yen
Did you delete any event/reminder programmatically ? Please help me the way you did that. thanks.Jamshed Alam

2 Answers

1
votes

This is working.

-(void)getCalendar
{
    NSString* newCalendarName = @"[email protected]";
    GTLQueryCalendar *query2 = [GTLQueryCalendar queryForCalendarsGetWithCalendarId:newCalendarName];

    [self.service executeQuery:query2
                      delegate:self
             didFinishSelector:@selector(displayResultWithTicket2:finishedWithObject:error:)];
}

But if I want to add something into my calendar.It will not work.I thing maybe problem is that I need scope kGTLAuthScopeCalendar to have read/write access. (I just find from Add event to google calendar from ios. Also note, that you have to authorize with the answer to said scope kGTLAuthScopeCalendar to have read/write access.)

0
votes

I fix the problem .My scope only calendarRealOnly. I finally add https://www.googleapis.com/auth/calendar.

[self.googleOAuth authorizeUserWithClienID:@"clienID"
                           andClientSecret:@"clentSecret"
                             andParentView:self.view
                                 andScopes:[NSArray arrayWithObjects:
                                            @"https://www.googleapis.com/auth/userinfo.profile",
                                            @"https://www.googleapis.com/auth/calendar",
                                            @"https://www.googleapis.com/auth/calendar.readonly",
                                            nil]
];


GTLCalendarCalendarListEntry*calendarListEntry=[GTLCalendarCalendarListEntry object];
calendarListEntry.identifier = @"[email protected]";

GTLQueryCalendar *queryInsertCalendarList = [GTLQueryCalendar queryForCalendarListInsertWithObject:calendarListEntry];
[self.service executeQuery:queryInsertCalendarList
                  delegate:self
         didFinishSelector:nil];