Android - 在checkin上上传foursquare图片时丢失文件错误

时间:2013-07-27 19:48:45

标签: android foursquare

使用httpPost在foursquare上上传图像时,会产生以下错误:

  

{“meta”:{“code”:400,“errorType”:“other”,“errorDetail”:“缺少文件   上传 “},” 响应“:{}}

以下是代码:

      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());
}

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

0 个答案:

没有答案