D
D
Dmitry2015-06-21 01:17:47
Facebook
Dmitry, 2015-06-21 01:17:47

Facebook video upload using graph api v2.3 (Resumable Upload). Can anyone help?

There is an application on Qt, designed for uploading photos / videos to social networks. networks (including FB). Now it works on the old version of Api (2.1), hence the 1GB file size limit and regular HTTP 504s. So the task is to transfer it to v2.3 with resumable downloads.
I pass authorization successfully. Init download - too, I get all the necessary parameters. But loading the first chunk ends with the following error:

{"error":{"message":"Service temporarily unavailable","type":"FacebookApiException","is_transient":true,"code":2,"error_subcode":1363030,"error_user_title":"Video Upload Time Out","error_user_msg":"Your video upload timed out before it could be completed. This is probably because of a slow network connection or because the video you're trying to upload is too large. Please try again."}}

As a connection, I'm sure. The chunk has a size of 1mb (I tried to upload smaller files - the chunk is smaller, the result is the same). So it's not all that obvious.
Here is a piece of code that sends a chunk (I have been conjuring over it for a long time, so it looks scary)
QNetworkRequest request;
request.setUrl(QUrl(QString("https://graph-video.facebook.com/v2.3/me/videos")));
QHttpMultiPart *body = new QHttpMultiPart(QHttpMultiPart::FormDataType);

_file = new QFile(filename);
_file->open(QIODevice::ReadOnly);

QHttpPart tokenPart, phasePart, sessionPart, offsetPart, dataPart;
tokenPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"access_token\""));
tokenPart.setBody(accessToken.toUtf8());

phasePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"upload_phase\""));
phasePart.setBody(phaseTransfer.toUtf8());

sessionPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"upload_session_id\""));
sessionPart.setBody(_sessionId.toUtf8());

offsetPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"start_offset\""));
offsetPart.setBody(QString::number(_startOffset).toUtf8());

QHttpPart dataPart;
dataPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"video_file_chunk\""));
QByteArray data = _file->read(_endOffset - _startOffset);
dataPart.setBody(data);

body->append(tokenPart);
body->append(phasePart);
body->append(offsetPart);
body->append(sessionPart);
body->append(dataPart);

_server->post(request, body);

The description I'm doing is here: https://developers.facebook.com/docs/graph-api/vid...
Maybe someone has come across something similar or even has a working example? I will be grateful for any help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question