2013-03-15 50 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

相關問題