The GMailDemo saves the Token on ini file but if I close the demo and then I run it again, TestTockens-RefreshAccess always fail and it has to go to DoAuth again.
The same is what I get in my own project. But, in the same project I have a similar situation using TAdvGCalendar and with this component the TestTockens-RefreshAccess works very well.
Hi,
I also tried to make it more simple in this way:
procedure TForm1.AdvGMail1ReceivedAccessToken(Sender: TObject);
begin
FWrite('c:\test\token', AdvGMail1.TokensAsString);
....
procedure TForm1.Button1Click(Sender: TObject);
var
Acc: Boolean;
begin
AdvGMail1.App.Key := GAppkey;
AdvGMail1.App.Secret := GAppSecret;
if AdvGMail1.App.Key <> '' then
begin
AdvGMail1.ClearTokens;
AdvGMail1.TokensAsString := FRead('c:\test\token');
Acc := AdvGMail1.TestTokens;
Connected := Acc;
if not Acc then
begin
AdvGMail1.RefreshAccess;
Acc := AdvGMail1.TestTokens;
if not Acc then
AdvGMail1.DoAuth
This is the same way I use for TAdvCalendar and it works. But no does not work with TAdvGmail, it always go to DoAuth.
Can you please make sure you are using the latest version of TMS VCL Cloud Pack?
If the problem persists, please try one of the following:
Remove the ClearTokens call from your code.
Enable logging to find out what the response data of the TestTokens call is.
Logging can be enabled by setting Logging to True and LogLevel to llDetail. The log file is created automatically in the Windows Documents folder.
Use the Connect call in combination with the OnConnected event instead of a combination of TestTokens/RefreshAccess/DoAuth and OnReceivedAcessToken.
Please note that, with your demo, after I "connect", I can send the mail, and it works. The problem if that, TestTokens and RefreshAccess always are returning false.
The log indicates insufficient authentication scopes for the request to retrieve labels.
This request is used to determine if the tokens are valid during the TestTokens call.
Can you please try if adding the following scopes resolves the issue?