We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
njclonch
9 years agoExplorer | Level 3
Access token is not being accepted from local server
After successfully receiving an access token from the `oauth2/authorize` endpoint, I have attempted to submit the access token to `sharing/get_shared_link_metadata` along with the URL of a shared lin...
Greg-DB
Dropbox Community Moderator
9 years agoCan you share your code and the full error response? Thanks in advance!
njclonch
9 years agoExplorer | Level 3
request:
public function getDropboxMetadata($url, $token)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.dropboxapi.com/2/sharing/get_shared_link_metadata');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['url' => $url]));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
response:
error: {
code: 401,
errors: {
0: {
domain: "global",
location: "Authorization",
locationType: "header",
message: "Invalid Credentials",
reason: "authError"
}
},
message: "Invalid Credentials"
}- Greg-DB9 years ago
Dropbox Community Moderator
Thanks! I just tried this out, and it's working for me.
Are you sure you're passing in a valid access token? I recommend printing out the $token just before you set the headers. It should be a 64 character string consisting of letters, numbers, and some symbols.- njclonch9 years agoExplorer | Level 3
My issue is not with the code itself, because I've received a successful response when I've used it on phpfiddle.com. My issue is that I'm getting an error response on my local virtual server, and I have no clue why. I am hoping you may have some insight.
- Greg-DB9 years ago
Dropbox Community Moderator
That indicates that something is wrong with the API request when made from your server. You'll need to inspect the request being made on your server. Since you're getting a 401, it seems likely that there is an issue with the access token. More generally, if you can print out the actual HTTP request that would likely be helpful.
I'd be happy to take a look, but please don't post any output that contains an actual access token of course.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!