0

I am making an application in qt/c++ and I wanted to upload images to a specific folder.I tried to get list of all folders but it does not provide me names of folder.I wanted to get their names so that user can select a particular folder from list of folders and I could upload to that specific folder.My code:http://pastebin.com/dBGkpeEj In response from this code I get kind,etag,selflink and items array in which each item has foll. fields:kind=drive#childReference,id,selflink,childlink. I want to get name of all folders
I got it solved by myself.Here's code to get list of all folders and subfolders in qt:

void googled::tryFolderListing(QNetworkReply *reply){
am = new QNetworkAccessManager;

QByteArray d = reply->readAll();
QString x = getValue(d,"access_token");
x = "Bearer " + x;
QUrl url("https://www.googleapis.com/drive/v2/files");
url.addQueryItem(QString("q").toAscii(),QString("mimeType = 'application/vnd.google-apps.folder'").toAscii());
QNetworkRequest request;
request.setUrl(url);
request.setRawHeader(QString("Content-Type").toAscii(),QString("application/json").toAscii());
request.setRawHeader(QString("Authorization").toAscii(),x.toAscii());
QObject::connect(am, SIGNAL(finished(QNetworkReply *)),
this, SLOT(uploadfinishedSlot(QNetworkReply *)));
am->get(request);

}

Cœur
  • 37,241
  • 25
  • 195
  • 267
saurabh
  • 110
  • 3
  • 12

1 Answers1

2

First, if you are interacting with user to choose specific file or folder from Drive, use Google Picker. Implementing your own picker is very inefficient and slow. And only with few lines of javascript code, you can do exactly what you want.

Second, you are using children.list which doesn't provide enough information for files. You should rather use Files.list() with query mimeType = 'application/vnd.google-apps.folder' and trashed = false and you will get all folder information you want.

Third, you forgot to implement pageToken. For some users who have a lot of files/folders, they might hit maxResults and query might not show all files/folders you want. Please take deeper look at sample codes.

JunYoung Gwak
  • 2,967
  • 3
  • 21
  • 35
  • After modifying code I sent a get request to this url:https://www.googleapis.com/drive/v2/files?q=mimeType%3D%27application%2Fvnd.google-apps.folder%27 but I get foll. error:"{ "error": { "errors": [ { "domain": "global", "reason": "invalid", "message": "Invalid Value", "locationType": "parameter", "location": "q" } ], "code": 400, "message": "Invalid Value" } } " My code:http://pastebin.com/7B8vKFnX @JunYoung Gwak Also I cannot use google picker for my application – saurabh Jun 21 '13 at 17:27
  • Error message says your query parameter, q, is in wrong format. There is no problem with query in your code. That probably means you are not parsing url correctly. Your query should look like this when you correctly parsed it: `GET https://www.googleapis.com/drive/v2/files?q=mimeType%3D'application%2Fvnd.google-apps.folder'&key={YOUR_API_KEY}` I'm not good at QT so this is the best I can help you. – JunYoung Gwak Jun 22 '13 at 03:00
  • do i need key parameter since I am already passing access token in header – saurabh Jun 22 '13 at 05:07
  • My bad, you don't need key parameter – JunYoung Gwak Jun 24 '13 at 17:43