9
private void postToWall(String msg) {
        Bundle parameters = new Bundle();
        // parameters.putString("method", "stream.publish");

        JSONObject attachment = new JSONObject();

        try {

            byte[] data = null;

            Bitmap bi = BitmapFactory.decodeResource(getResources(),
                    R.drawable.bluerib);
            // Bitmap bi =
            // BitmapFactory.decodeFile("http://demos.com/LangGuage/medal_1.png");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bi.compress(Bitmap.CompressFormat.JPEG, 30, baos);
            data = baos.toByteArray();

            // Bundle params = new Bundle();
            // params.putByteArray("picture", data);
            attachment.put("type", "image");
            // attachment.put("picture", data);
            attachment.put("name", "LangGuage");
            attachment.put("message", msg);
            attachment.put("src", "http://demos.com/LangGuage/medal_1.png");
            attachment.put("href", "http://www.abc.com");
            // attachment.put("href",
            // "http://hwsdemos.com/LangGuage/medal_1.png");

            parameters.putString(Facebook.TOKEN, facebook.getAccessToken());
            parameters.putString("attachment", attachment.toString());
            String response = facebook.request("me/photos", parameters, "POST");

            System.out.println("----responce" + response);

            if (response.contains("Duplicate status message")) {
                progressHandler.sendEmptyMessage(1);
                resp = 1;

            } else if (response == null || response.equals("")
                    || response.equals("false") || response.contains("error")) {
                Log.d("error", "error response");
            } else {
                progressHandler.sendEmptyMessage(0);
                resp = 0;

            }

        } catch (Exception e) {
            Log.e(TAG, "Posting fail");

            e.printStackTrace();
            // finish();
        }

    }

我的应用程序支持 facebook 的单点登录。我不想使用对话框。每当我尝试在附件中同时发布图像和消息时,我都会发现:

{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}
4

1 回答 1

4

请参阅此处的照片图 POST 请求的文档https://developers.facebook.com/docs/reference/api/user/#photos

您的图像数据应进入“源”字段,其他可用字段只有“消息”、“地点”和“no_story”。“src”、“名称”、“href”不是有效字段。

于 2013-03-18T18:32:30.947 回答