Hi again,
ePirat, oh, if only it were that simple; I would have been done a long time ago.
Andy Piper, can you ask one of the server-side programmers to help? It shouldn’t take much of his/her time.
I’ve tried several approaches; I’ll show them to you below. Take them to one of the programmers and ask which
approach is correct, if either; and why both approaches get “media parameter is missing.” response.
Here’s the first approach:
BasicHttpEntityEnclosingRequest httpEntityEnclosingRequest =
new BasicHttpEntityEnclosingRequest( POST, TWITTER_ENDPOINT_UPLOAD_MEDIA );
// I tried the following line, but it causes authorization required failure
//new BasicHttpEntityEnclosingRequest( POST, TWITTER_ENDPOINT_UPLOAD_MEDIA+"?command=INIT&media_type=image/jpeg&total_bytes=6046" );
// Since we setContentType("application/x-www-form-urlencoded"),
// it seems reasonable that we should send a UrlEncodedFormEntity.
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("command", "INIT"));
formparams.add(new BasicNameValuePair("media_type", "image/png"));
formparams.add(new BasicNameValuePair("total_bytes", "6046"));
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams, UTF_8);
httpEntityEnclosingRequest.setEntity( urlEncodedFormEntity );
urlEncodedFormEntity.setContentType("application/x-www-form-urlencoded");
Here’s the second approach:
StringEntity stringEntity;
stringEntity = new StringEntity( "command=INIT&media_type=image%2Fjpeg&total_bytes=6046", UTF_8);
stringEntity.setContentType("application/x-www-form-urlencoded");
httpEntityEnclosingRequest.setEntity(stringEntity);
Both approaches proceed on to this code:
httpEntityEnclosingRequest.setParams(httpParams);
httpEntityEnclosingRequest.addHeader("Authorization", authorization_header_string);
httpEntityEnclosingRequest.addHeader("Content-Type","x-www-form-urlencoded" );
HttpContext httpContext = getHttpContext(httpHost, httpClientConnection);
HttpResponse httpResponse = getHttpResponse(
httpParams, httpClientConnection, httpContext, httpEntityEnclosingRequest);
Both approaches get the response:
{“errors”:[{“code”:38,“message”:“media parameter is missing.”}]}.
Do this for me and I’ll send you a box of candy every day for a year,
or if you prefer I’ll buy you a yacht.