Facebook SDK 3.0将图片上传到Facebook页面(不在相册中)

时间:2013-04-05 08:22:25

标签: java android facebook facebook-graph-api

大家好我在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;

2 个答案:

答案 0 :(得分:0)

以下代码适合我。我正在使用最新的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();

答案 1 :(得分:0)

  

“我想要做的是在Facebook页面上发布消息   手机内存或SD-CARD中的图片/图片。“

目前无法做到这一点。您可以从SDCARD(而不是通过URL)上传照片的唯一地方是特定的相册。