Commented gmail api sample batched request.
This commit is contained in:
		
							parent
							
								
									9748e0c37a
								
							
						
					
					
						commit
						a10a78ab47
					
				
					 2 changed files with 44 additions and 7 deletions
				
			
		
							
								
								
									
										40
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										40
									
								
								src/main.cpp
									
										
									
									
									
								
							|  | @ -29,6 +29,7 @@ | ||||||
| #include "miscellaneous/debugging.h" | #include "miscellaneous/debugging.h" | ||||||
| #include "miscellaneous/feedreader.h" | #include "miscellaneous/feedreader.h" | ||||||
| #include "miscellaneous/iconfactory.h" | #include "miscellaneous/iconfactory.h" | ||||||
|  | #include "network-web/oauth2service.h" | ||||||
| #include "network-web/silentnetworkaccessmanager.h" | #include "network-web/silentnetworkaccessmanager.h" | ||||||
| #include "network-web/webfactory.h" | #include "network-web/webfactory.h" | ||||||
| 
 | 
 | ||||||
|  | @ -38,12 +39,11 @@ | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #include <QDebug> | #include <QDebug> | ||||||
|  | #include <QHttpMultiPart> | ||||||
| #include <QThread> | #include <QThread> | ||||||
| #include <QTimer> | #include <QTimer> | ||||||
| #include <QTranslator> | #include <QTranslator> | ||||||
| 
 | 
 | ||||||
| #include <network-web/oauth2service.h> |  | ||||||
| 
 |  | ||||||
| #if defined (Q_OS_MAC) | #if defined (Q_OS_MAC) | ||||||
| extern void disableWindowTabbing(); | extern void disableWindowTabbing(); | ||||||
| 
 | 
 | ||||||
|  | @ -183,20 +183,50 @@ int main(int argc, char* argv[]) { | ||||||
|      "vppQtxrEeBkImiXcjGYl9NxZ", |      "vppQtxrEeBkImiXcjGYl9NxZ", | ||||||
|      "https://mail.google.com/"); |      "https://mail.google.com/"); | ||||||
| 
 | 
 | ||||||
|  |      srv->setRefreshToken("1/RKE3oohSoTHE54L0IPflvndK-DcI7l0of3lVdLa1Q9Q"); | ||||||
|      QObject::connect(srv, &OAuth2Service::authCodeObtained, [](QString auth_code) { |      QObject::connect(srv, &OAuth2Service::authCodeObtained, [](QString auth_code) { | ||||||
|      int a = 5; |      int a = 5; | ||||||
|      }); |      }); | ||||||
|      QObject::connect(srv, &OAuth2Service::authFailed, []() { |      QObject::connect(srv, &OAuth2Service::authFailed, []() { | ||||||
|      int a = 5; |      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; |      int a = 5; | ||||||
|      }); |      }); | ||||||
|      QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) { |      QObject::connect(srv, &OAuth2Service::tokensRetrieveError, [](QString err, QString desc) { | ||||||
|      int a = 5; |      int a = 5; | ||||||
|      }); |      }); | ||||||
|      srv->login(); |      srv->login(); */ | ||||||
|    */ |  | ||||||
| 
 | 
 | ||||||
|   // Enter global event loop.
 |   // Enter global event loop.
 | ||||||
|   return Application::exec(); |   return Application::exec(); | ||||||
|  |  | ||||||
|  | @ -170,6 +170,8 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) { | ||||||
| 
 | 
 | ||||||
|   qDebug() << "Token response:" << json_document.toJson(); |   qDebug() << "Token response:" << json_document.toJson(); | ||||||
| 
 | 
 | ||||||
|  |   IOFactory::writeTextFile("c.json", json_document.toJson()); | ||||||
|  | 
 | ||||||
|   if (root_obj.keys().contains("error")) { |   if (root_obj.keys().contains("error")) { | ||||||
|     QString error = root_obj.value("error").toString(); |     QString error = root_obj.value("error").toString(); | ||||||
|     QString error_description = root_obj.value("error_description").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)); |     setTokensExpireIn(QDateTime::currentDateTime().addSecs(expires)); | ||||||
|     setAccessToken(root_obj.value(QL1S("access_token")).toString()); |     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(); |     qDebug() << "Obtained refresh token" << refreshToken() << "- expires on date/time" << tokensExpireIn(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue