我希望用戶將文件上傳到Google雲端硬盤,但不是根文件。 Children資源只允許從根目錄列出文件夾(這很有意義),但不會將文件夾的名稱放在JSON響應中。將文件上傳到隨機文件夾中
我無法使用Parent資源,因爲fileID不存在,還因爲我需要用戶查看文件夾(在其各自的層次中)並選擇他們選擇的文件夾。這是我迄今試過的東西
void DriveClass::listFileFolderDrive(const QString& folderID){
QUrl url("https://www.googleapis.com/drive/v2/files/" + folderID + "/children");
//qDebug()<<" url for About Drive: "<< url;
QNetworkRequest* request = new QNetworkRequest(url);
request->setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request->setRawHeader("Authorization", QString("Bearer %1").arg(this->_oAuth2->token()).toLatin1());
QNetworkReply* reply = m_networkManager->get(*request);
bool result = connect(reply, SIGNAL(finished()), this, SLOT(onlistFileFolderDriveFinished()));
Q_ASSERT(result);
Q_UNUSED(result);
}
其中folderID是「root」。我得到的迴應是:
QVariant(QVariantMap, QMap(("etag", QVariant(QString, ""dyf6dc5nFpQUIZ2nJvOu2LyLJk8/bD3mjJonFeCjTc8Eu8VRx_DzPtg"")) ("items" , QVariant(QVariantList, (QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_Ycab1hhT3I0T3ptMDg")) ("id" , QVariant(QString, "0B_0rcYNi_Ycab1hhT3I0T3ptMDg")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_Ycab1hhT3I0T3ptMDg"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcabXdJd21CeWRHUXM")) ("id" , QVariant(QString, "0B_0rcYNi_YcabXdJd21CeWRHUXM")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcabXdJd21CeWRHUXM"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaM1ZCOXBaZzJSNmc")) ("id" , QVariant(QString, "0B_0rcYNi_YcaM1ZCOXBaZzJSNmc")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaM1ZCOXBaZzJSNmc"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaSmtNMmRlTld5QkU")) ("id" , QVariant(QString, "0B_0rcYNi_YcaSmtNMmRlTld5QkU")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaSmtNMmRlTld5QkU"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaY0I0czA4djNLT1U")) ("id" , QVariant(QString, "0B_0rcYNi_YcaY0I0czA4djNLT1U")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaY0I0czA4djNLT1U"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaTW8zZklsNnFNTDBmQ1dodi1yTFhqX2s4SzNr")) ("id" , QVariant(QString, "0B_0rcYNi_YcaTW8zZklsNnFNTDBmQ1dodi1yTFhqX2s4SzNr")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaTW8zZklsNnFNTDBmQ1dodi1yTFhqX2s4SzNr"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/1_eVyijBnZPvFfn4WewtScnlSXRFpXInmop-AUD6Jp5nSV4rnxL4-IpLZ6uoR")) ("id" , QVariant(QString, "1_eVyijBnZPvFfn4WewtScnlSXRFpXInmop-AUD6Jp5nSV4rnxL4-IpLZ6uoR")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/1_eVyijBnZPvFfn4WewtScnlSXRFpXInmop-AUD6Jp5nSV4rnxL4-IpLZ6uoR"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/0B_0rcYNi_YcaYmNmZTEwMzYtNjgzZC00MjJkLWFmYWQtZmRlODc4OTEwZTVh")) ("id" , QVariant(QString, "0B_0rcYNi_YcaYmNmZTEwMzYtNjgzZC00MjJkLWFmYWQtZmRlODc4OTEwZTVh")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/0B_0rcYNi_YcaYmNmZTEwMzYtNjgzZC00MjJkLWFmYWQtZmRlODc4OTEwZTVh"))) ) , QVariant(QVariantMap, QMap(("childLink", QVariant(QString, "https://www.googleapis.com/drive/v2/files/1CHu3CzJ23I6WS3J8rOIpT5szN8r8mTOxztiWixwXafQ")) ("id" , QVariant(QString, "1CHu3CzJ23I6WS3J8rOIpT5szN8r8mTOxztiWixwXafQ")) ("kind" , QVariant(QString, "drive#childReference")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/0AP0rcYNi_YcaUk9PVA/children/1CHu3CzJ23I6WS3J8rOIpT5szN8r8mTOxztiWixwXafQ"))) )) )) ("kind" , QVariant(QString, "drive#childList")) ("selfLink" , QVariant(QString, "https://www.googleapis.com/drive/v2/files/root/children"))) )
我希望這已經夠清楚了。我在QVariant中解析它,以便在ListView中使用結果。從我學習谷歌驅動器文檔,需要一個文件有一個文件夾ID插入之前可以實現。而且我沒有要上傳的新文件的文件夾ID。
我需要向我們展示您嘗試過的內容,並描述您在使用當前解決方案時遇到的任何問題。請閱讀http://stackoverflow.com/help/how-to-ask – DaImTo
謝謝。我已經請求了根子文件夾的列表。這個問題已被重新編輯。 –