抱歉的重複的問題可能是,但我真的面臨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
}
}
請有人告訴我在哪裏我根據需求做了改變。
只需刪除'params.putByteArray( 「圖片報」 數據);'這一行和它的相應代碼。 –
我已經測試過,但不工作 –
是你在做fb登錄第一次的任何機會或直接調用這段代碼 –