2013-11-28 40 views
1

抱歉的重複的問題可能是,但我真的面臨Facebook的Android應用程序的問題,我只想發佈消息在Facebook牆上,我能夠發佈圖像與文本,但我要張貼純文本,請告訴我,我錯了我在這裏是我的代碼發佈從Android應用程序的Facebook上只有短信

的圖片+文字

public void postImageonWall() { 
    Log.i("Alok", "Test"); 
    Bundle params = new Bundle(); 
    // Inflate Edit text for Facebook Message 

    params.putString("method", "photos.upload"); 
    params.putString("app_id", mAPP_ID); // I've tried with/without this, 
              // same result 
    String message1 = "Test here "; 
    params.putString("message", message1); 

    // int r = jj - 1; 
    // 
    // Bitmap b = BitmapFactory.decodeFile("/sdcard/D&P post/postimage" + r 
    // + ".jpg"); 

    // Get image from drawable 
    Bitmap b = BitmapFactory 
      .decodeResource(getResources(), R.drawable.test); 
    Log.i("Bitmap Image is here", "Bitmap" + b); 
    if (b != null) { 
     Log.i("Bitmap", "value"); 
    } else { 
     Log.i("Bitmap", "null"); 
    } 

    byte[] data = null; 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    b.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
    data = baos.toByteArray(); 
    if (data != null) { 
     params.putByteArray("picture", data); 
     Log.i("final", "value" + message); 
     params.putString("caption", message); 
     Log.e("PHOTOUPLOAD", "Attemping an upload..."); 

     AsyncFacebookRunner mAsyncRunner = new    AsyncFacebookRunner(facebook); 
     mAsyncRunner.request(null, params, "POST", 
       new SampleUploadListener(), null); 
     Log.e("PHOTOUPLOAD", "Attemping an upload..."); 
    } 

} 

這兒,這是工作的代碼是簡單的點擊聽者: -

公共類SampleUploadListener擴展BaseRequestListener {

public void onComplete(final String response, final Object state) { 
     try { 

      Log.d("Facebook-Example", "Response: " + response.toString()); 
      JSONObject json = Util.parseJson(response); 
      final String src = json.getString("src"); 

     } catch (JSONException e) { 
      Log.w("Facebook-Example", "JSON Error in response"); 
     } catch (FacebookError e) { 
      Log.w("Facebook-Example", "Facebook Error: " + e.getMessage()); 
     } 
    } 

    @Override 
    public void onFacebookError(FacebookError e, Object state) { 
    } 

    public void onComplete(String response) { 
     // TODO Auto-generated method stub 

    } 

    public void onIOException(IOException e) { 
     // TODO Auto-generated method stub 

    } 

    public void onFileNotFoundException(FileNotFoundException e) { 
     // TODO Auto-generated method stub 

    } 

    public void onMalformedURLException(MalformedURLException e) { 
     // TODO Auto-generated method stub 

    } 

    public void onFacebookError(FacebookError e) { 
     // TODO Auto-generated method stub 

    } 
} 

請有人告訴我在哪裏我根據需求做了改變。

+0

只需刪除'params.putByteArray( 「圖片報」 數據);'這一行和它的相應代碼。 –

+0

我已經測試過,但不工作 –

+0

是你在做fb登錄第一次的任何機會或直接調用這段代碼 –

回答

0

試試這個方法

public void postToWall(String message) { 
Bundle params = new Bundle(); 
params.putString("message", message); 

// Uses the Facebook Graph API 
try { 
    facebook.request("/me/feed", params, "POST"); 
    this.finish(); 
} catch (FileNotFoundException e) { 
    e.printStackTrace(); 
} catch (MalformedURLException e) { 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

}

+0

對不起Virag,但不工作請儘可能幫我 –

+0

請嘗試上面的方法張貼在FB牆 –

0

嘗試類似的following.It工作了我的所有項目,

private void postToFacebook(String review) { 
     mProgress.setMessage("Posting ..."); 
     mProgress.show(); 
     AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook); 

     Bundle params = new Bundle(); 
     params.putString("name", title); 
     params.putString("link", link); 
     mAsyncFbRunner.request("me/feed", params, "POST", 
       new WallPostListener()); 

    } 
     private Handler mRunOnUi = new Handler(); 
    private final class WallPostListener extends BaseRequestListener { 
     public void onComplete(final String response) { 
      mRunOnUi.post(new Runnable() { 

       public void run() { 
        mProgress.cancel(); 
        Toast.makeText(SVG_View.this, 
          "Posted to Facebook", Toast.LENGTH_SHORT).show(); 

       } 
      }); 

     } 

    } 
+0

你在做什麼首先登錄fb,然後調用這段代碼,我想使用fb sdk 3.0發佈messasge,但不成功 –

相關問題