как отправить файл на гугл диск с Qt? - PullRequest
0 голосов
/ 25 апреля 2018

Привет, я начинающий программист. Я создал приложение в QT, но наткнулся на синхронизацию файлов с Google Drive (что должно делать мое приложение). Я следил за статьей о том, как пройти аутентификацию в Google API от здесь :

и удалось заставить его работать правильно.

Вот код, который работает:

#include <QString>
#include <QFile>
#include <QTextStream>
#include <QOAuth2AuthorizationCodeFlow>
#include <QDesktopServices>
#include <QObject>
#include <QJsonObject>
#include <QJsonDocument>
#include <QOAuthHttpServerReplyHandler>
#include <QJsonArray>

void FileIO::sendToDrive(){

     auto google = new QOAuth2AuthorizationCodeFlow;
     google->setScope("https://www.googleapis.com/auth/drive");
     QObject::connect(google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser,
        &QDesktopServices::openUrl);


    QFile jsonFile("E:/Documents/QTProjects/swwe/autho.json");
    jsonFile.open(QFile::ReadOnly);
    QJsonDocument document;
    document = QJsonDocument().fromJson(jsonFile.readAll());


    const auto object = document.object();
    const auto settingsObject = object["web"].toObject();
    const QUrl authUri(settingsObject["auth_uri"].toString());
    const auto clientId = settingsObject["client_id"].toString();
    const QUrl tokenUri(settingsObject["token_uri"].toString());
    const auto clientSecret(settingsObject["client_secret"].toString());
    const auto redirectUris = settingsObject["redirect_uris"].toArray();
    const QUrl redirectUri(redirectUris[0].toString()); // Get the first URI
    const auto port = static_cast<quint16>(redirectUri.port()); // Get the port



    google->setAuthorizationUrl(authUri);
    google->setClientIdentifier(clientId);
    google->setAccessTokenUrl(tokenUri);
    google->setClientIdentifierSharedKey(clientSecret);

    auto replyHandler = new QOAuthHttpServerReplyHandler(port);
    google->setReplyHandler(replyHandler);

    google->grant();

    auto reply = google->get(QUrl("https://www.googleapis.com/plus/v1/people/me"));

 }

для правильной аутентификации приложения. Тогда я не знаю, как отправить один текстовый файл на Google Drive. Я видел примеры из документации Google, но не знаю, как поместить их в контекст моего кода.

Может ли кто-нибудь дать мне пример того, как отправить один текстовый файл в этом контексте?

Приветствия. Duo

...