我想在google驱动器的根目录(因此我没有包含id字段)创建文件夹,但是我收到错误代码400,解析错误。 我的代码:
void googled::createfolder(QNetworkReply* reply){
QUrl url("https://www.googleapis.com/drive/v2/files");
QByteArray data = reply->readAll();
//qDebug() << data;
QString x = getValue(data,"access_token");
QString y = "Bearer " + x;
m_n = new QNetworkAccessManager;
QObject::connect(m_n, SIGNAL(finished(QNetworkReply *)),
this, SLOT(foldercreateSlot(QNetworkReply *)));
QByteArray arr;
QNetworkRequest request;
QString str;
str += QString("{");
str += "\r\t";
str += QString("\"title\": \"SMP\"");
str += "\r\n";
str += "\r\t";
str += QString("\"mimeType\": \"application/vnd.google-apps.folder\"");
str += "\r\n";
str += QString("}");
request.setUrl(url);
qDebug() << str;
request.setRawHeader("Content-Type","application/json");
request.setRawHeader("Authorization",y.toLatin1());
m_n->post(request,arr);
}
答案 0 :(得分:0)
您不会在请求正文中包含任何边界和文件内容。一个合适的身体如下所示。
POST /upload/drive/v2/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Authorization: your_auth_token
Content-Type: multipart/related; boundary="foo_bar_baz"
Content-Length: number_of_bytes_in_entire_request_body
--foo_bar_baz
Content-Type: application/json; charset=UTF-8
{
"title": "My File"
}
--foo_bar_baz
Content-Type: image/jpeg
blob data
--foo_bar_baz--
已经在Drive SDK's great documentation上解释了。在阅读可用的文档之前,请不要提问。