I think I am missing something, because before I used GoogleCalendar from TMS Cloud pack without difficulty. However GoogleCalendar in FNC doesn't seem to work. Here is what I did:
var
CloudGCalendar : TTMSFNCCloudGoogleCalendar;
ACalendar : TTMSFNCCloudGoogleCal;
Begin
CloudGCalendar:= TTMSFNCCloudGoogleCalendar.Create(nil);
CloudGCalendar.Authentication.ClientID := 'MyClientId';
CloudGCalendar.Authentication.Secret := 'MySecret';
CloudGCalendar.Authentication.CallBackURL := 'http://127.0.0.1:8888'; //this is my url, I double checked
With CloudGCalendar Do
Begin
Logging := True;
PersistTokens.Location := plIniFile;
PersistTokens.Key := '.\gcal.ini';
PersistTokens.Section := 'tokens';
LoadTokens;
Connect; // NO ERROR HERE, everything seems to go well, at first it asks for credentials
End; // With CloudGCalendar Do
CloudGCalendar.GetCalendars; // Here CloudGCalendar.Calendars.count gives me 0
//This should give me the default calendar, however the debugger says CloudGCalendar.Items.Count=0
CloudGCalendar.GetCalendar('',Date,Date+EncodeTime(23, 59, 59, 0));
With your demo I can use the same credentials , but it is not easily understandable for me: there are a lot of .pas files with a lot of classes and no comments at all. The help is very short and I cannot use it as other Delphi related helps e.g. clicking on an object and it shows all the properties and methods in details, with examples.
For example in the help it only says about AddCalendar that '...used to initialize the Calendar', but there is nothing written about the Calendar class in details. I needed to check the source code and there are more properties than it is mentioned in the help.
Please help me resolving this issue. Thank you very much in advance!
Please note that TMS FNC Cloud Pack calls are asynchronous. You can use the OnGetCalendars event in combination with GetCalendars to access the retrieved calendar data.
Please make sure to add the TTMSFNCCloudGoogleCal object to the TTMSFNCCloudGoogleCalendar Calendars collection when creating it.
Example:
var
ACalendar: TTMSFNCCloudGoogleCal;
begin
ACalendar := TTMSFNCCloudGoogleCal.Create(TMSFNCCloudGoogleCalendar1.Calendars);
ACalendar.Summary := 'Teszt 01';
TMSFNCCloudGoogleCalendar1.AddCalendar(ACalendar);
end;
Var I:Integer;
for I := 0 to CloudGoogleCalendar.Items.Count - 1 do
Begin
ShowMessage( 'Google item :'+CloudGoogleCalendar.Items[I].Summary);
End;
end;
And the interesting thing is, that the code above never works the first time, I need to call it twice, to fill the items. Why is that?
It looks like I do the same way (using GetCalendars and GetCalendar events), but with this code it fills the items at the second call only. Can you please correct the code below?
procedure TMainForm.Button1Click(Sender: TObject);
begin
CloudGoogleCalendar.Connect;
CloudGoogleCalendar.GetCalendars;
end;
procedure TMainForm.CloudGoogleCalendarGetCalendar(Sender: TObject;
const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
Var I:Integer;
for I := 0 to CloudGoogleCalendar.Items.Count - 1 do
Begin
ShowMessage(CloudGoogleCalendar.Items[I].Summary);
End;
end;
Here is a sample code that is working as expected:
procedure TForm4.Button1Click(Sender: TObject);
begin
TMSFNCCloudGoogleCalendar1.Authentication.ClientID := '';
TMSFNCCloudGoogleCalendar1.Authentication.Secret := '';
TMSFNCCloudGoogleCalendar1.Authentication.CallBackURL := '';
TMSFNCCloudGoogleCalendar1.Connect;
end;
procedure TForm4.TMSFNCCloudGoogleCalendar1Connected(Sender: TObject);
begin
TMSFNCCloudGoogleCalendar1.GetCalendars;
end;
procedure TForm4.TMSFNCCloudGoogleCalendar1GetCalendars(Sender: TObject;
const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
i: integer;
begin
ListBox1.Clear;
for i := 0 to TMSFNCCloudGoogleCalendar1.Calendars.Count - 1 do
begin
ListBox1.Items.Add(TMSFNCCloudGoogleCalendar1.Calendars[i].Summary);
end;
TMSFNCCloudGoogleCalendar1.GetCalendar(TMSFNCCloudGoogleCalendar1.Calendars[0].ID);
end;
procedure TForm4.TMSFNCCloudGoogleCalendar1GetCalendar(Sender: TObject;
const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
i: integer;
begin
ListBox2.Clear;
for i := 0 to TMSFNCCloudGoogleCalendar1.Items.Count - 1 do
begin
ListBox2.Items.Add(TMSFNCCloudGoogleCalendar1.Items[i].Summary);
end;
end;