Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared link already exists #130

Open
feralheart opened this issue Jul 6, 2018 · 1 comment
Open

Shared link already exists #130

feralheart opened this issue Jul 6, 2018 · 1 comment

Comments

@feralheart
Copy link

I testing the shared link function. I generated one, but when I requests the same function I got this error:

{"error_summary": "shared_link_already_exists/.", "error": {".tag": "shared_link_already_exists"}}

How to check if shared link exists and than use that or create a link if it don't exists?

@dval
Copy link

dval commented Jan 7, 2020

You can handle this one of two ways. You can check the file metadata for sharing info, or you can just request the link and handle the error.

Checking for sharing info:
https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_shared_links

$pathToFile = "/someFolder/someFile";
$response = $dropbox->postToAPI("/sharing/list_shared_links", [ "path" => $pathToFile ]);
$data = $response->getDecodedBody();

$data will have a links[0].link_permissions object in it.
If there is no share, links will be an empty array.

Handling the error and continuing:

You can just get the share data from the error, then you don't have to make a second call.

$data = "";
try{
    $pathToFile = "/someFolder/someFile";
    $response = $dropbox->postToAPI("/sharing/list_shared_links", [ "path" => $pathToFile ]);
    $data = $response->getDecodedBody();
} catch (DropboxClientException $e) {
    $response = $e->getMessage();
    $dataObj = json_decode($response, $assoc=true);
    $data = $dataObj['error']['shared_link_already_exists']['metadata'];
}
echo json_encode($data);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants