Search code examples
phpfile-uploaddropbox

Dropbox api createshareableling not working


I have some code created, which uploads a sample file and then should give the shareable url back, but it gives an error:

Fatal error: Call to undefined function createShareableLink() in /home/u983866586/public_html/db/dropbox.php on line 52    

My code:

    # Include the Dropbox SDK libraries
     require_once "Dropbox/autoload.php";
use \Dropbox as dbx;

$appInfo = dbx\AppInfo::loadFromJsonFile("keys.json");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");

$authorizeUrl = $webAuth->start();

$authCode = "something";

$accessToken= "M4OYlxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$accountInfo = $dbxClient->getAccountInfo();

//~ print_r($accountInfo);

$f = fopen("working-draft.txt", "rb");
$result = $dbxClient->uploadFile("/working-draft.txt", dbx\WriteMode::add(), $f);
fclose($f);
//~ print_r($result);

$folderMetadata = $dbxClient->getMetadataWithChildren("/");
print_r($folderMetadata);

$f = fopen("working-draft.txt", "w+b");
$fileMetadata = $dbxClient->getFile("/working-draft.txt", $f);
fclose($f);

createShareableLink("/working-draft.txt");

The function createSareableLink is from: http://dropbox.github.io/dropbox-sdk-php/api-docs/v1.1.x/source-class-Dropbox.Client.html#1007-1038 but it is not working.

Arend-Jan


Solution

  • I think you just forgot to use "$dbxClient->" before "createShareableLink".
    So that should work for you:

    $linkToShare = $dbxClient->createShareableLink("/working-draft.txt");
    echo $linkToShare;