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

How to use getRefreshedAccessToken ? #200

Open
Clemweb opened this issue Oct 12, 2022 · 4 comments
Open

How to use getRefreshedAccessToken ? #200

Clemweb opened this issue Oct 12, 2022 · 4 comments

Comments

@Clemweb
Copy link

Clemweb commented Oct 12, 2022

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

@Pixelao
Copy link

Pixelao commented Nov 25, 2022

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 👍

@stccorp
Copy link

stccorp commented Jan 20, 2023

That function does not exists

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

@saracubillas
Copy link

@Pixelao what version are you using?

@Pixelao
Copy link

Pixelao commented Sep 8, 2023

@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

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

4 participants