How to get dropbox user id?

6k views Asked by At

I want to create php page for upload file into my dropbox. I have got key and secret key from my dropbox account.

From here I got coding for dropbox but I did not get user id. How can I get user id of dropbox.

https://www.dropbox.com/developers/core/start/php

list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
print "Access Token: " . $accessToken . "\n";
2

There are 2 answers

1
Andy Jones On

I assume you're using the standard PHP Dropbox SDK

$client = new Dropbox\Client($accessToken);
$info = $client->getAccountInfo();
echo $info["uid"];
0
Hiren Raiyani On
<?php
error_reporting(E_ALL);
require_once("DropboxClient.php");

// you have to create an app at https://www.dropbox.com/developers/apps and enter   details below:
$dropbox = new DropboxClient(array(
'app_key' => "", 
'app_secret' => "",
    'app_full_access' => true,
),'en');

handle_dropbox_auth($dropbox); // see below

// if there is no upload, show the form
if(empty($_FILES['the_upload'])) {
?>
<form enctype="multipart/form-data" method="POST" action="">
<p>
<label for="file">Upload File</label>
<input type="file" name="the_upload" />
</p>
<p><input type="submit" name="submit-btn" value="Upload!"></p>
</form>
<?php } else { 

    $upload_name = $_FILES["the_upload"]["name"];
echo "<pre>";
echo "\r\n\r\n<b>Uploading $upload_name:</b>\r\n";
$meta = $dropbox->UploadFile($_FILES["the_upload"]["tmp_name"], $upload_name);
print_r($meta);
echo "\r\n done!";
echo "</pre>";
}

to run before you have to authorized in dropbox apps