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

Suddenly getting error Class "djchen\OAuth2\Client\Provider\Fitbit" not found #1028

Open
ShailzaDev opened this issue Apr 2, 2024 · 0 comments

Comments

@ShailzaDev
Copy link

ShailzaDev commented Apr 2, 2024

djChen Library was working fine but suddenly getting error for it class not found
use djchen\OAuth2\Client\Provider\Fitbit;
protected function fetchDataForToken($token,$interval)
{
$tokenDetail = json_decode($token['token'], true);
$accessToken = $tokenDetail['access_token'];
$fitbitUserId = $tokenDetail['values']['user_id'];
$refreshToken = $tokenDetail['refresh_token'];

    $expirationTime = $tokenDetail['expires'];

    $currentTimestamp = time();
    $provider = new Fitbit([
        'clientId'     => env('FITBIT_CLIENT_ID'),
        'clientSecret' => env('FITBIT_CLIENT_SECRET'),
        'redirectUri'  => env('FITBIT_REDIRECT_URI'),
    ]);

    $isExpired = $currentTimestamp >= $expirationTime;
    if ($isExpired) {
            $newAccessToken = $provider->getAccessToken('refresh_token', [
                'refresh_token' => $refreshToken
            ]);
            if($newAccessToken)
            {
                $accessToken = $newAccessToken->getToken();                  
                $refreshToken = $newAccessToken->getRefreshToken();
                // Update token details
                $tokenDetail['access_token'] = $accessToken;
                $tokenDetail['refresh_token'] = $refreshToken;
                $tokenDetail['expires'] = $newAccessToken->getExpires();

                $token['token'] = json_encode($tokenDetail);
                $this->info('token updated successfully');    
                $token->save();
                $this->info('Token updated successfully');
            }        
    } 
   }
@ShailzaDev ShailzaDev changed the title djChen/ Suddenly getting error Class "djchen\OAuth2\Client\Provider\Fitbit" not found Apr 2, 2024
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

1 participant