2013-11-28 45 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,但不成功 –

相关问题