2013-03-15 16 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(); 
     } 

    } 

Uygulamam tek oturum halinde destekliyor için Facebook. Diyalogları kullanmak istemiyorum. Bir ekinde birlikte bir görüntü ve mesajı göndermek için deneyin zaman ben yakalamak:{ "hata": { "mesaj": "OAuthException", "kod": "" "yazın (# 324) yükleme dosyası gerektirir" 324}}

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

bu 'attachment.put (" type ") kaldır , "image"); ' – Nezam

+0

Bu satırı kaldırdıktan sonra kontrol ettim.ama yine aynı hatayı al. –

cevap

4

burada fotoğraflar grafiği POST isteği için dokümanlar bakın https://developers.facebook.com/docs/reference/api/user/#photos

Resminiz verileri "kaynak" alanına gitmeli

ve diğer kullanılabilir alanlar "ileti", "yer" ve "no_story" dir. "src", "name", "href" geçerli alanlar değil.

+0

Hala doğru mu? n bir url aracılığıyla bir görüntü gönderin, bu durumda "kaynak" yerine "src" yersiniz: https://developers.facebook.com/docs/graph-api/reference/v2.0/user/photos/ –

+1

Bir görüntüyü "source" veya "url" kullanarak gönderebilirsiniz. –

+0

Ayrıca bkz. Https://developers.facebook.com/docs/php/FacebookFile/ – here

İlgili konular