T
T
TriKrista2019-04-08 15:00:20
API
TriKrista, 2019-04-08 15:00:20

How to get a list of files from Google Drive?

I'm trying to populate a list like this:

GoogleDrive::GoogleDrive(QObject *parent) : QObject(parent) {
    auth = new QOAuth2AuthorizationCodeFlow;
    auth->setScope("email");

    connect(auth, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);

    connect(auth, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status status) {
            if (status == QAbstractOAuth::Status::Granted) {
                emit authenticated();
            }
        });

    connect(this, &GoogleDrive::authenticated, this, &GoogleDrive::sendRequest);

    QString val;
    QFile file;
    file.setFileName("/path/client.json");
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    val = file.readAll();
    file.close();

    QJsonDocument document = QJsonDocument::fromJson(val.toUtf8());
    const auto object = document.object();
    const auto settingsObject = object["installed"].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());
    const auto port = static_cast<quint16>(redirectUri.port());

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

    auto replyHandler = new QOAuthHttpServerReplyHandler(port);
    auth->setReplyHandler(replyHandler);
    auth->grant();
}

void GoogleDrive::sendRequest() {
    reply = auth->get(QUrl("https://www.googleapis.com/drive/v3/files"));
    connect(reply, &QNetworkReply::finished, this, &GoogleDrive::replyFinished);
    connect(reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error),
        [=](QNetworkReply::NetworkError error) {
            qDebug() << "error:" << error << " (" << reply->errorString() << ")";
        });
}

void GoogleDrive::replyFinished() {
    qDebug() << "answer:" << reply->readAll();
}

but instead of a list, this response comes:

{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp" : " https://code.google.com/apis/console "
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
David, 2019-04-08
@rockstardavid

You ran into limits, read the answer carefully - Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question