Commented gmail api sample batched request.
This commit is contained in:
parent
9748e0c37a
commit
a10a78ab47
2 changed files with 44 additions and 7 deletions
42
src/main.cpp
42
src/main.cpp
|
@ -29,6 +29,7 @@
|
|||
#include "miscellaneous/debugging.h"
|
||||
#include "miscellaneous/feedreader.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "network-web/silentnetworkaccessmanager.h"
|
||||
#include "network-web/webfactory.h"
|
||||
|
||||
|
@ -38,12 +39,11 @@
|
|||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
#include <QHttpMultiPart>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QTranslator>
|
||||
|
||||
#include <network-web/oauth2service.h>
|
||||
|
||||
#if defined (Q_OS_MAC)
|
||||
extern void disableWindowTabbing();
|
||||
|
||||
|
@ -176,27 +176,57 @@ int main(int argc, char* argv[]) {
|
|||
qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->loadAllExpandStates();
|
||||
|
||||
/*
|
||||
OAuth2Service* srv = new OAuth2Service(
|
||||
OAuth2Service * srv = new OAuth2Service(
|
||||
"https://accounts.google.com/o/oauth2/auth",
|
||||
"https://accounts.google.com/o/oauth2/token",
|
||||
"369069180494-j66bgeciouinec1eem7fhvj6qm0as7q3.apps.googleusercontent.com",
|
||||
"vppQtxrEeBkImiXcjGYl9NxZ",
|
||||
"https://mail.google.com/");
|
||||
|
||||
srv->setRefreshToken("1/RKE3oohSoTHE54L0IPflvndK-DcI7l0of3lVdLa1Q9Q");
|
||||
QObject::connect(srv, &OAuth2Service::authCodeObtained, [](QString auth_code) {
|
||||
int a = 5;
|
||||
});
|
||||
QObject::connect(srv, &OAuth2Service::authFailed, []() {
|
||||
int a = 5;
|
||||
});
|
||||
QObject::connect(srv, &OAuth2Service::tokensReceived, [](QString acc, QString ref, int exp) {
|
||||
QObject::connect(srv, &OAuth2Service::tokensReceived, [srv](QString acc, QString ref, int exp) {
|
||||
|
||||
QHttpMultiPart* multi = new QHttpMultiPart(srv);
|
||||
QHttpPart p1;
|
||||
QHttpPart p2;
|
||||
|
||||
multi->setContentType(QHttpMultiPart::ContentType::MixedType);
|
||||
p1.setRawHeader("Content-Type", "application/http");
|
||||
p2.setRawHeader("Content-Type", "application/http");
|
||||
p1.setBody("GET /gmail/v1/users/me/messages\r\n");
|
||||
p2.setBody("GET /gmail/v1/users/me/labels\r\n");
|
||||
multi->append(p1);
|
||||
multi->append(p2);
|
||||
QNetworkRequest req;
|
||||
|
||||
auto bearer = srv->bearer();
|
||||
req.setRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit());
|
||||
|
||||
req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/batch"));
|
||||
auto* repl = SilentNetworkAccessManager::instance()->post(req, multi);
|
||||
|
||||
//req.setUrl(QUrl::fromUserInput("https://www.googleapis.com/gmail/v1/users/me/labels"));
|
||||
//auto* repl = SilentNetworkAccessManager::instance()->get(req);
|
||||
|
||||
QObject::connect(repl, &QNetworkReply::finished, [repl]() {
|
||||
auto resp = repl->readAll();
|
||||
auto a = 8;
|
||||
|
||||
IOFactory::writeTextFile("b.html", resp);
|
||||
});
|
||||
|
||||
int a = 5;
|
||||
});
|
||||
QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) {
|
||||
int a = 5;
|
||||
});
|
||||
srv->login();
|
||||
*/
|
||||
srv->login(); */
|
||||
|
||||
// Enter global event loop.
|
||||
return Application::exec();
|
||||
|
|
|
@ -170,6 +170,8 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) {
|
|||
|
||||
qDebug() << "Token response:" << json_document.toJson();
|
||||
|
||||
IOFactory::writeTextFile("c.json", json_document.toJson());
|
||||
|
||||
if (root_obj.keys().contains("error")) {
|
||||
QString error = root_obj.value("error").toString();
|
||||
QString error_description = root_obj.value("error_description").toString();
|
||||
|
@ -183,7 +185,12 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) {
|
|||
|
||||
setTokensExpireIn(QDateTime::currentDateTime().addSecs(expires));
|
||||
setAccessToken(root_obj.value(QL1S("access_token")).toString());
|
||||
setRefreshToken(root_obj.value(QL1S("refresh_token")).toString());
|
||||
|
||||
const QString refresh_token = root_obj.value(QL1S("refresh_token")).toString();
|
||||
|
||||
if (!refresh_token.isEmpty()) {
|
||||
setRefreshToken(refresh_token);
|
||||
}
|
||||
|
||||
qDebug() << "Obtained refresh token" << refreshToken() << "- expires on date/time" << tokensExpireIn();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue