大家好,我是android开发的菜鸟,我正在尝试实现一项功能,该功能将允许用户在Facebook页面上发布消息,并可以选择从该设备SD卡上传图片/图像。
我正在使用Facebook SDK 3.0
我设法使其工作了,但没有在Facebook页面墙上,而是通过用户个人资料时间轴。
提前致谢。
*编辑*
case REQUEST_PICK_IMAGE:
if (resultCode == RESULT_OK) {
imageUri = intent.getData();
AsyncFacebookRunner mAsyncFbRunner1 = new AsyncFacebookRunner(mFacebook);
Log.d(TAG, imageUri.toString() + " " + imageUri.getPath());
Bundle params = new Bundle();
try {
in = new FileInputStream(getRealPathFromURI(imageUri));
buf = new BufferedInputStream(in);
byte[] bMapArray= new byte[buf.available()];
buf.read(bMapArray);
params.putByteArray("picture", bMapArray);
} catch (IOException e) {
e.printStackTrace();
}
params.putString("method", "photos.upload");
params.putString("caption", "sample post via gallery");
mAsyncFbRunner1.request("PAGE_ID" + "/feed", params, "POST", new PhotoUploadListener(), null);
}
break;
最佳答案
以下代码对我有用。我正在使用最新的Facebook SDK 3.0
showLoader(getResources().getString(R.string.sharing_on_facebook_wall));
Request.Callback callback= new Request.Callback()
{
public void onCompleted(com.facebook.Response response)
{
hideLoader();
FacebookRequestError error = response.getError();
if (error != null)
Toast.makeText(getApplicationContext(), error.getErrorMessage(), Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "Posted successfully.", Toast.LENGTH_LONG).show();
}
};
Session session = Session.getActiveSession();
Bundle postParams = new Bundle();
postParams.putString("name", "Title");
postParams.putString("link", "http://www.stackoverflow.com");
postParams.putString("description", "description");
postParams.putString("caption", "PictureTestApp");
postParams.putString("picture", imageUrl);
Request request = new Request(session, "me/feed", postParams, HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();