use of org.brunocvcunha.instagram4j.requests.internal.InstagramUploadVideoJobRequest in project instagram4j by brunocvcunha.
the class InstagramUploadVideoRequest method execute.
@Override
public StatusResult execute() throws ClientProtocolException, IOException {
HttpPost post = createHttpRequest();
String uploadId = String.valueOf(System.currentTimeMillis());
post.setEntity(createMultipartEntity(uploadId));
try (CloseableHttpResponse response = api.getClient().execute(post)) {
api.setLastResponse(response);
int resultCode = response.getStatusLine().getStatusCode();
String content = EntityUtils.toString(response.getEntity());
log.info("First phase result " + resultCode + ": " + content);
post.releaseConnection();
InstagramUploadVideoResult firstPhaseResult = parseJson(content, InstagramUploadVideoResult.class);
if (!firstPhaseResult.getStatus().equalsIgnoreCase("ok")) {
throw new RuntimeException("Error happened in video upload session start: " + firstPhaseResult.getMessage());
}
String uploadUrl = firstPhaseResult.getVideo_upload_urls().get(3).get("url").toString();
String uploadJob = firstPhaseResult.getVideo_upload_urls().get(3).get("job").toString();
StatusResult uploadJobResult = api.sendRequest(new InstagramUploadVideoJobRequest(uploadId, uploadUrl, uploadJob, videoFile));
log.info("Upload result: " + uploadJobResult);
if (!uploadJobResult.getStatus().equalsIgnoreCase("ok")) {
throw new RuntimeException("Error happened in video upload submit job: " + uploadJobResult.getMessage());
}
StatusResult thumbnailResult = configureThumbnail(uploadId);
if (!thumbnailResult.getStatus().equalsIgnoreCase("ok")) {
throw new IllegalArgumentException("Failed to configure thumbnail: " + thumbnailResult.getMessage());
}
return api.sendRequest(new InstagramExposeRequest());
}
}
Aggregations