Get link/share url not working with DropBox?

I've added to the CloudStorageServicesDemo app to add a Get_Link button to retrieve a shared link url to a selected existing file. Authentication works ok, I can navigate around the files in my DropBox account, but when I try to get a link or share url, it's always empty. Am I missing a step?

procedure TForm1.Get_LinkClick(Sender: TObject);
var
  it: TTMSFNCCloudDropBoxItem;
  link_string, share_string, fname : String ;
begin
it := TMSFNCCloudDemoListBox1.Items[TMSFNCCloudDemoListBox1.ItemIndex].DataObject as TTMSFNCCloudDropBoxItem;

fname := it.FileName ;
share_string := it.Share ;
link_string :=  it.Link ;
end;

Many thanks for any advice,

Adam

Hi,

Please note that requesting the Share url is an asynchronous operation, so the value won't be available immediately.

You can use the GetShare call in combination with the OnGetShare event instead:

Example:

public
  procedure GetShare(Sender: TObject; const AShare: string; const ARequestResult: TTMSFNCCloudBaseRequestResult);
end;

procedure TForm1.GetShare(Sender: TObject; const AShare: string;
  const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
  share_string : String ;
begin
  share_string := AShare ;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  it: TTMSFNCCloudDropBoxItem;
begin
  it := TMSFNCCloudDemoListBox1.Items[TMSFNCCloudDemoListBox1.ItemIndex].DataObject as TTMSFNCCloudDropBoxItem;

  TTMSFNCCloudDropBox(TMSFNCCloudStorageServices1.Storage).GetShare(it);
  TTMSFNCCloudDropBox(TMSFNCCloudStorageServices1.Storage).OnGetShare := GetShare;
end;

Hi Bart,
Thanks for the quick response.
I've put your code into the CloudStorageServicesDemo and the GetShare event is triggered very quickly after the button click, however the share_string always comes back as empty ''.
Am I right in thinking there's nothing else I need to do to register this event?
In the meantime, I can switch to GoogleDrive and use the WebContentLink instead and everything works just fine.
Best regards,
Adam

If the event gets triggered it should be registered correctly.
Possibly there is an error in the request for retrieving the share link.
You can try to enable logging or inspect the request result by tracing the source code to find out what is going wrong.

Hi Adam,
Bart's suggestion work well for me ....
Try to do this ...
In your form declare something like Done : Boolean; LinkStr : String; and insert one label (LinkLabel)

Change procedure TForm1.Button1Click(Sender: TObject) to

procedure TForm1.Button1Click(Sender: TObject);
Var it: TTMSFNCCloudDropBoxItem;
begin
  LinkStr='';
  Done:=False;
  TTMSFNCCloudDropBox(CloudStorage.Storage).OnGetShare := GetShare;
  repeat // 1
    it := CloudListbox.Items[CloudListBox.ItemIndex].DataObject as TTMSFNCCloudDropBoxItem;
    TTMSFNCCloudDropBox(CloudStorage.Storage).GetShare(it);
    repeat // 2
      Sleep(100);
      Application.ProcessMessages;
    until Done ;
  until LinkStr<>'';
  LinkLabel.Caption:=LinkStr;
end;

and, just for example, change

procedure TForm1.GetShare(Sender: TObject; const AShare: string;
  const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
  share_string : String ;
begin
  share_string := AShare ;
  LinkStr:=share_string;
  Done:=True;
end;

With this code all work ..... and the selected item link is returned in linkStr.
Due the fact that Getshare is "asynchronous" you need to wait some time in order to finish operation.
The "waste" time is rapresented by repeat until block (2), when the link is retuned ...Done is true and all is done.

1: This repeat unitl is need because sometimes, i don't know why, at first round LinkStr is empty and on second round return the value. In this way each time you click on the button, you'll have the rigth link.

Hope you can resolve the problem.

Regards

Daniele

Hi Daniele,

Many thanks for taking the time to reply in detail. I've implemented your suggestions but never get a non-blank link return. I had to add a iterations count to prevent the code going into an infinite loop. I'll take a look at the source code in more detail later on, but for now I'll keep working on the Google Drive option as it seems simpler and more reliable at this stage.

Thanks again,

Adam

procedure TForm1.ShareClick(Sender: TObject);
var
ci: TTMSFNCCloudItem ;
it: TTMSFNCCloudDropBoxItem;
iterations : integer ;
begin
ci := TTMSFNCCloudItem(TMSFNCCloudDemoListBox1.Items[TMSFNCCloudDemoListBox1.ItemIndex].DataObject) ;

if ( ci is TTMSFNCCloudDropBoxItem) then
begin
LinkStr := '';
iterations := 0 ;
Done := False;
TTMSFNCCloudDropBox(TMSFNCCloudStorageServices1.Storage).OnGetShare := GetShare;

repeat // 1
it := (TMSFNCCloudDemoListBox1.Items[TMSFNCCloudDemoListBox1.ItemIndex].DataObject) as TTMSFNCCloudDropBoxItem ;
TTMSFNCCloudDropBox(TMSFNCCloudStorageServices1.Storage).GetShare(it);

repeat // 2
  iterations := iterations + 1 ;
  Search_Box.Text := iterations.ToString ;
  Sleep(100);
  Application.ProcessMessages;
until Done  ;

until (LinkStr <> '' ) or (iterations > 100) ;
Link.text := LinkStr;
end;

if ( ci is TTMSFNCCloudGoogleDriveItem) then
Link.Text := (ci as TTMSFNCCloudGoogleDriveItem).WebContentLink ;

end;

procedure TForm1.GetShare(Sender: TObject; const AShare: string;
const ARequestResult: TTMSFNCCloudBaseRequestResult);
var
share_string : String ;
begin
share_string := AShare ;
LinkStr := share_string;
Done := True;
end;