我希望用户将文件上传到Google云端硬盘,但不能上传到根版。 Children资源只允许从根目录列出文件夹(这是有意义的),但不会将文件夹的名称放在JSON响应中。
我无法使用父资源,因为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是&#34; root&#34;。我得到的回应是:
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中使用结果。从我对google驱动器文档的研究中,需要一个文件才能在插入之前获得一个folderID。我没有要上传的新文件的folderID。
答案 0 :(得分:0)
一些指示......
folder_id in parents
执行files.list。答案 1 :(得分:0)
parents:[{ "id" : "id of the folder, use root for root folder" }]
谢谢@pinoyyid。