1

在使用 httpPost 在foursquare上上传图像时,会生成以下错误作为响应:

{"meta":{"code":400,"errorType":"other","errorDetail":"缺少文件上传"},"response":{}}

下面是代码:

      Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);

    byte [] ba = bao.toByteArray();
    String ba1=Base64.encodeToString(ba, 0);

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("venueId", "5177a5b8e4b0de6e7df647b4"));
nameValuePairs.add(new BasicNameValuePair("checkinId",name));
nameValuePairs.add(new BasicNameValuePair("image",ba1));

try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("https://api.foursquare.com/v2/photos/add?v=20130726&oauth_token="+ActivityWebView.accessToken);
    httppost.setHeader("Content-Type",
            "image/jpeg");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
   long i= response.getEntity().getContentLength();
  String res=  inputStreamToString(response.getEntity().getContent()).toString();
  Log.v("response", ""+res);
  System.out.println("resssssssssssssssssssssssssssssssssssssssss"+res);
  System.out.println("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"+i);
  Toast.makeText(getApplicationContext(),"response"+res, Toast.LENGTH_LONG).show();

} catch(Exception e) {
    Log.e("log_tag", "Error in http connection "+e.toString());
}

这可能是由于上传图像时出错。

4

0 回答 0