大家好,我是 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();
关于java - Facebook SDK 3.0 上传图片到facebook页面(不在相册),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15829119/