2012-09-07 242 views
-1

我可以成功发布Facebook上的文本,但是当我在Facebook上发布图片消息时,我无法在Facebook上发布图片,我也没有收到任何类型的错误,但只是变得无法在Facebook上发布图片

 private static final String[] PERMISSIONS = new String[] { "publish_stream", "read_stream", "offline_access" }; 

和我的代码

 json.isNull("id") = null 

我已经使用权限是

 try { 
      // String response = authenticatedFacebook.request("me"); 
      // JSONObject obj = Util.parseJson(response); 
      path = Environment.getExternalStorageDirectory().toString() + "/Diegodeals"; 
      Bundle parameters = new Bundle(); 
      parameters.putString("message", txtTitle.getText().toString() + "\n" + txtDesc.getText().toString()); 
      File file = new File(path, "diegodeals.jpg"); 
      System.out.println(file.getAbsolutePath()); 
      Bitmap bitmap = getResizedBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()), 120, 120); 
      byte[] data = null; 
      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
      bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
      data = baos.toByteArray(); 
      if (data != null) { 
       parameters.putByteArray("picture", data); 
      } 
      parameters.putString("access_token", authenticatedFacebook.getAccessToken()); 
      authenticatedFacebook.request("me"); 
      String response = authenticatedFacebook.request("me/feed", parameters, "POST"); 
      JSONObject json; 
      try { 
       json = Util.parseJson(response); 
       if (!json.isNull("id")) { 
        isWallPostSuccess = false; 
        return "failed"; 
       } else { 
        isWallPostSuccess = true; 
        return "success"; 
       } 
      } catch (FacebookError e) { 
       isWallPostSuccess = false; 
       e.printStackTrace(); 
      } 

     } catch (Throwable e) { 
      isWallPostSuccess = false; 
      e.printStackTrace(); 
     } 
     return null; 
    } 

    public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { 
     int width = bm.getWidth(); 
     int height = bm.getHeight(); 
     float scaleWidth = ((float) newWidth)/width; 
     float scaleHeight = ((float) newHeight)/height; 
     // CREATE A MATRIX FOR THE MANIPULATION 
     Matrix matrix = new Matrix(); 
     // RESIZE THE BIT MAP 
     matrix.postScale(scaleWidth, scaleHeight); 

     // RECREATE THE NEW BITMAP 
     Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false); 
     return resizedBitmap; 
    } 
+0

虽然如果我发布带图片的文本,但唯一的文本会成功发布,但不是图片... –

回答

0

参数picture接收图片的URL,而不是图片二进制本身。将图片放在一些可公开访问的服务器上,并将其链接到那里,或使用Facebook的图形API /photos图片上传机制。

+0

你好Laalto如果我使用92x92尺寸的图像比它将成功发布图像与此图片参数 –

0

将Facebook上的照片上传到自己的墙上的正确方法是将“照片”和“标题”参数绑定到“我/照片”上。请注意,你的“图片”和“消息”,“我/饲料”,这是行不通的。

在你的例子中,它看起来像你有一个本地图像,你想上传。这是如何做到这一点:

Bundle params = new Bundle(); 
params.putByteArray(
     "photo", 
     Util.getByteArrayFromDrawable(getResources().getDrawable(
       R.drawable.picture))); 
params.putString("caption", "test message here"); 
mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener()); 

否则,提供对“图片报”参数中的URL(而不是字节数组),并在“标题”参数字符串,并张贴到“我/饲料”。

+0

,但杰西陈我想张贴照片到Facebook不上传照片,这就是为什么我用我/饲料,我测试了这个例子,如果我已经使用小图像比当时的形象和标题将成功张贴,但有时它不会 –