dropbox-php-sdk icon indicating copy to clipboard operation
dropbox-php-sdk copied to clipboard

How to use getRefreshedAccessToken ?

Open Clemweb opened this issue 2 years ago • 4 comments

Hello,

I need to share specifics docs from my Dropbox to end user.

All is ok to get and use the AccessToken from my back office. But the token expire like mentioned in doc, so I need to refresh token for my front office users.

How use getRefreshedAccessToken ??

The documentation is very poor and not clear: why passed $accessToken to it ?

Somebody can share me a full example ?

Thanks

Clemweb avatar Oct 12 '22 14:10 Clemweb

Hello @Clemweb, this example script will return a URL where you have to login with the account you want to authenticate in the application, when you login it will give you a one-time auth key, but im using this fork https://github.com/internacionalweb/dropbox-php-sdk

Example:

use Kunnu\Dropbox\Dropbox;
use Kunnu\Dropbox\DropboxApp;
use Kunnu\Dropbox\Authentication\DropboxAuthHelper;

$appKey = 'YOUR_APP_KEY';
$appSecret = 'YOUR_APP_SECRET';
$authToken = 'YOUR_APP_AUTH_TOKEN';

$app = new DropboxApp($appKey, $appSecret, $authToken);

$dropboxClient = new Dropbox($app);

$authHelper = $dropboxClient->getAuthHelper();
$authHelper->setAccessTokenType(DropboxAuthHelper::TOKEN_ACCESS_TYPE_OFFLINE);

echo 'AUTH URL: ' . $authHelper->getAuthUrl();

With that key use $authHelper->getAccessToken('YOUR_AUTH_KEY') It will return an AccessToken object in which we can find the refresh_token. This is a permanent token with which we can generate Short Live tokens for a duration of 4 hours.

Example:

use Kunnu\Dropbox\Dropbox;
use Kunnu\Dropbox\DropboxApp;

$appKey = 'YOUR_APP_KEY';
$appSecret = 'YOUR_APP_SECRET';
$authToken = 'YOUR_APP_AUTH_TOKEN';

$app = new DropboxApp($appKey, $appSecret, $authToken);
$dropboxClient = new Dropbox($app);
$authHelper = $dropboxClient->getAuthHelper();

var_dump($authHelper->getAccessToken('YOUR_AUTH_KEY'));

I hope this helps 👍

Pixelao avatar Nov 25 '22 09:11 Pixelao

That function does not exists

Fatal error: Uncaught Error: Call to undefined method Kunnu\Dropbox\Authentication\DropboxAuthHelper::setAccessTokenType()

stccorp avatar Jan 20 '23 17:01 stccorp

@Pixelao what version are you using?

saracubillas avatar Apr 21 '23 07:04 saracubillas

@saracubillas

@Pixelao what version are you using?

I'm using a fork, which introduces new functionality for working with short-lived tokens. https://github.com/internacionalweb/dropbox-php-sdk

Pixelao avatar Sep 08 '23 12:09 Pixelao