0

我目前可以使用以下方式发布到公共页面墙上:

JSONObject json = new JSONObject();
json.put("message", "I'm on your wall");



Request req = Request.newPostRequest(getSession(), "PowerCardSoftware/feed", GraphObject.Factory.create(json), new Callback() {
        @Override
        public void onCompleted(Response response) {
            if(response.getError() != null)
                Log.e("FRAGACTIVITY", response.getError().toString());
            Toast.makeText(getBaseContext(), "I hacked your facebook!", Toast.LENGTH_SHORT).show();
        }
    });
    Request.executeBatchAsync(req);

我也想将用户拍摄的照片张贴到公共墙上。我尝试使用 Bundle 而不是 JSONObject 并使用以下每一行:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
postPhoto.compress(CompressFormat.JPEG, 100, baos);
params.putByteArray("picture", baos.toByteArray());
params.putByteArray("source", baos.toByteArray());

他们都给我这样的错误 - errorMessage: (#100) 图片 URL 格式不正确

任何人都知道如何在不使用 facebook sdk 中已弃用的功能/对象的情况下将照片发布到其他人的 facebook 墙上?

4

3 回答 3

2

这是我上传本地存储在手机上的照片的代码:

        Request request6 = Request.newUploadPhotoRequest(
                session,
                ((BitmapDrawable) getResources().getDrawable(
                        R.drawable.picture)).getBitmap(), callback6);
        RequestAsyncTask task6 = new RequestAsyncTask(request6);
        task6.execute();

这是上传到您自己的墙上。无法选择其他收件人的原因是由于 2 月份的重大更改将禁止发布到其他人的墙上。

请参阅我之前的回答

编辑:

上传照片的最佳方式是什么?

你可以试试这个,看看这是否有效?

    Bundle parameters = new Bundle();
    parameters.putParcelable("picture", YOUR_BITMAP_HERE);
    parameters.putString("message", "my message for the page");

    return new Request(session, "PowerCardSoftware/feed", parameters, HttpMethod.POST, callback);

我可以使用 newUploadPhotoRequest() 添加消息吗?

不,要在照片中添加消息,您不会使用newUploadPhotoRequest. 如果您深入研究源代码,它只是 a 的包装器Request,因此与方法相同,但添加一个附加参数 ,message带有您想要的消息,然后执行它。我没有亲自验证它,但它应该可以工作。如果没有,请告诉我。

于 2013-01-02T22:05:30.183 回答
1

这是我的解决方案。我参考了Jesse Chen的回答并做了一些修改。

Bitmap image = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "demo.jpg");
Bundle parameters = new Bundle();
parameters.putParcelable("source", image);
parameters.putString("message", "my message for the page");
Request request = new Request(Session.getActiveSession(), "me/photos", parameters, HttpMethod.POST, new Request.Callback() {
    @Override
    public void onCompleted(Response response) {
        showPublishResult(mainActivity.getString(R.string.photo_post), response.getGraphObject(), response.getError());
    }
});
request.executeAsync();
于 2013-04-01T14:57:24.563 回答
0

您可以查看 facebookSDK 项目 /tests 文件夹并搜索关键字 newPostRequest。示例代码如下

GraphObject statusUpdate = GraphObject.Factory.create();
                String message = "message";
                statusUpdate.setProperty("message", message);
                statusUpdate.setProperty("link", "http://stackoverflow.com/questions/14129546/android-post-picture-to-facebook-public-page-wall#");
            Request request = Request.newPostRequest(Session.getActiveSession(), "me/feed", statusUpdate, new Callback() {

                @Override
                public void onCompleted(Response response) {

                }
            });
            request.executeAsync();
于 2014-04-16T04:48:35.277 回答