对不起,重复的问题可能是,但我真的遇到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 :(得分: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();
}
}
答案 1 :(得分:0)
尝试以下内容。它适用于我的所有项目,
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();
}
});
}
}