2013-03-15 52 views
9
private void postToWall(String msg) { 
     Bundle parameters = new Bundle(); 
     // parameters.putString("method", "stream.publish"); 

     JSONObject attachment = new JSONObject(); 

     try { 

      byte[] data = null; 

      Bitmap bi = BitmapFactory.decodeResource(getResources(), 
        R.drawable.bluerib); 
      // Bitmap bi = 
      // BitmapFactory.decodeFile("http://demos.com/LangGuage/medal_1.png"); 
      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
      bi.compress(Bitmap.CompressFormat.JPEG, 30, baos); 
      data = baos.toByteArray(); 

      // Bundle params = new Bundle(); 
      // params.putByteArray("picture", data); 
      attachment.put("type", "image"); 
      // attachment.put("picture", data); 
      attachment.put("name", "LangGuage"); 
      attachment.put("message", msg); 
      attachment.put("src", "http://demos.com/LangGuage/medal_1.png"); 
      attachment.put("href", "http://www.abc.com"); 
      // attachment.put("href", 
      // "http://hwsdemos.com/LangGuage/medal_1.png"); 

      parameters.putString(Facebook.TOKEN, facebook.getAccessToken()); 
      parameters.putString("attachment", attachment.toString()); 
      String response = facebook.request("me/photos", parameters, "POST"); 

      System.out.println("----responce" + response); 

      if (response.contains("Duplicate status message")) { 
       progressHandler.sendEmptyMessage(1); 
       resp = 1; 

      } else if (response == null || response.equals("") 
        || response.equals("false") || response.contains("error")) { 
       Log.d("error", "error response"); 
      } else { 
       progressHandler.sendEmptyMessage(0); 
       resp = 0; 

      } 

     } catch (Exception e) { 
      Log.e(TAG, "Posting fail"); 

      e.printStackTrace(); 
      // finish(); 
     } 

    } 

我的应用程序支持单一登录Facebook的。我不想使用对话框。 每当我尝试在附件张贴图片和消息一起我赶上:{“error”:{“message”:“(#324)需要上传文件”,“type”:“OAuthException”,“code”:324}}

{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}} 
+0

remove this attachment.put(“type” ,“image”);' – Nezam 2013-03-15 09:42:01

+0

我在删除这行后检查,但仍然得到相同的错误 – 2013-03-15 09:52:57

回答

4

请参阅该文档为这里的照片图POST请求https://developers.facebook.com/docs/reference/api/user/#photos

你的图像数据应该进入“源”字段,只有其他可用的字段是“message”,“place”和“no_story”。“src”,“name”,“href”不是有效字段。

+0

这是否仍然是真的?我读了你可以n通过网址发布图片,在这种情况下,您可以使用“src”而不是“来源”: https://developers.facebook.com/docs/graph-api/reference/v2.0/user/photos/ – 2014-06-30 13:04:10

+1

您可以使用“来源”或“网址”发布图片。 – 2014-07-02 00:07:24

+0

参见https://developers.facebook.com/docs/php/FacebookFile/ – here 2015-07-17 07:06:33

相关问题