diff --git a/src/Cloud/OAuthDialog.cpp b/src/Cloud/OAuthDialog.cpp index 3c7f216dc..b4f4ad4a9 100644 --- a/src/Cloud/OAuthDialog.cpp +++ b/src/Cloud/OAuthDialog.cpp @@ -278,6 +278,8 @@ OAuthDialog::onAccessTokenReceived(QString token, QString tokenSecret) if (site == WITHINGS) { service->setSetting(GC_WITHINGS_TOKEN, token); service->setSetting(GC_WITHINGS_SECRET, tokenSecret); + appsettings->setCValue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN, ""); + info = QString(tr("Nokia Health (Withings) authorization was successful.")); } diff --git a/src/Cloud/OAuthManager.cpp b/src/Cloud/OAuthManager.cpp index 66792ef65..7474add77 100644 --- a/src/Cloud/OAuthManager.cpp +++ b/src/Cloud/OAuthManager.cpp @@ -256,6 +256,8 @@ OAuthManager::onAccessTokenReceived(QString token, QString tokenSecret) if (site == WITHINGS) { service->setSetting(GC_WITHINGS_TOKEN, token); service->setSetting(GC_WITHINGS_SECRET, tokenSecret); + appsettings->setCValue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN, ""); + info = QString(tr("Nokia Health (Withings) authorization was successful.")); } diff --git a/src/Cloud/WithingsDownload.cpp b/src/Cloud/WithingsDownload.cpp index 5a4f1ffb8..e8b988765 100644 --- a/src/Cloud/WithingsDownload.cpp +++ b/src/Cloud/WithingsDownload.cpp @@ -99,11 +99,21 @@ WithingsDownload::getBodyMeasures(QString &error, QDateTime from, QDateTime to, QUrl postData; #endif + //appsettings->setCValue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN, ""); + qDebug() << "refresh_token" << appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN, QString("%1:%2").arg(strToken).arg(strSecret)); + + QString refresh_token = appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN).toString(); + if (refresh_token.isEmpty()) + refresh_token = QString("%1:%2").arg(strToken).arg(strSecret); + qDebug() << "refresh_token" << refresh_token; + postData.addQueryItem("grant_type", "refresh_token"); postData.addQueryItem("client_id", GC_NOKIA_CLIENT_ID ); postData.addQueryItem("client_secret", GC_NOKIA_CLIENT_SECRET ); - postData.addQueryItem("refresh_token", appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN, QString("%1:%2").arg(strToken).arg(strSecret)).toString() ); + postData.addQueryItem("refresh_token", refresh_token ); + + qDebug() << appsettings->cvalue(context->athlete->cyclist, GC_NOKIA_REFRESH_TOKEN, QString("%1:%2").arg(strToken).arg(strSecret)).toString(); QUrl url = QUrl( "https://account.withings.com/oauth2/token" ); emit downloadStarted(100);