如何使用Qt将文件发送到谷歌硬盘?

时间:2018-04-25 08:55:12

标签: c++ qt google-drive-api qt5

嗨,我是一名乞讨程序员。我在QT中创建了一个应用,但偶然发现文件同步到谷歌驱动器(我的应用应该这样做)。我已经关注了如何从here对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"));

 }

正确验证应用。然后,我不知道如何将单个文本文件发送到谷歌硬盘。我已经看过谷歌文档中的示例,但我不知道如何将它们放在我的代码的上下文中。

任何人都可以举例说明如何在此上下文中发送单个文本文件吗?

干杯。 朵

0 个答案:

没有答案