use of org.brunocvcunha.instagram4j.requests.internal.InstagramExposeRequest in project instagram4j by brunocvcunha.
the class InstagramUploadPhotoRequest method execute.
@Override
public InstagramConfigurePhotoResult execute() throws ClientProtocolException, IOException {
if (uploadId == null) {
uploadId = String.valueOf(System.currentTimeMillis());
}
HttpPost post = createHttpRequest();
post.setEntity(createMultipartEntity());
try (CloseableHttpResponse response = api.getClient().execute(post)) {
api.setLastResponse(response);
int resultCode = response.getStatusLine().getStatusCode();
String content = EntityUtils.toString(response.getEntity());
log.info("Photo Upload result: " + resultCode + ", " + content);
post.releaseConnection();
StatusResult result = parseResult(resultCode, content);
if (!result.getStatus().equalsIgnoreCase("ok")) {
throw new RuntimeException("Error happened in photo upload: " + result.getMessage());
}
InstagramConfigurePhotoResult configurePhotoResult = api.sendRequest(new InstagramConfigurePhotoRequest(imageFile, uploadId, caption));
log.info("Configure photo result: " + configurePhotoResult);
if (!configurePhotoResult.getStatus().equalsIgnoreCase("ok")) {
throw new IllegalArgumentException("Failed to configure image: " + configurePhotoResult.getMessage());
}
StatusResult exposeResult = api.sendRequest(new InstagramExposeRequest());
log.info("Expose result: " + exposeResult);
if (!exposeResult.getStatus().equalsIgnoreCase("ok")) {
throw new IllegalArgumentException("Failed to expose image: " + exposeResult.getMessage());
}
return configurePhotoResult;
}
}
use of org.brunocvcunha.instagram4j.requests.internal.InstagramExposeRequest 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