dropbox-php-sdk
dropbox-php-sdk copied to clipboard
How to use getRefreshedAccessToken ?
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
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 👍
That function does not exists
Fatal error: Uncaught Error: Call to undefined method Kunnu\Dropbox\Authentication\DropboxAuthHelper::setAccessTokenType()
@Pixelao what version are you using?
@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