【问题标题】:{"error":{"message":"(#100) Missing message or attachment","type":"OAuthException","code":100}}{"error":{"message":"(#100) 缺少消息或附件","type":"OAuthException","code":100}}
【发布时间】:2013-03-16 05:39:27
【问题描述】:

这是我的代码

    private void postToWall(String msg) {
    Bundle parameters = new Bundle();

    JSONObject attachment = new JSONObject();

    String myjosn="{\"name\":\"LangGuage\",\"href\":\"http://www.hunkatech.com\",\"caption\":\" \",\"description\":\""+messageToPost+"\",\"media\":[{\"type\":\"image\",\"src\":\"http://hwsdemos.com/LangGuage/medal_1.png\",\"href\":\"http://www.hunkatech.com\"}],\"properties\":{\"Powered by:\":{\"text\":\"Hunka Technology Pvt. Ltd.\",\"href\":\"http://www.hunkatech.com\"}}}";  

            try {



        parameters.putString(Facebook.TOKEN, facebook.getAccessToken());

            parameters.putString("attachment",myjosn.toString());


        String response = facebook.request("me/feed", 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();

    }

}

我想在 Facebook 墙上发布带有图像的消息。我的 json 是正确的,我已经在 json 格式化程序编辑器上检查了它。我收到了以下异常。需要如何解决它的建议。

更新:我的消息和图片在以下代码的帮助下发布:

parameters.putString("link", "http://www.hunkatech.com");
parameters.putString("picture", "http://hwsdemos.com/LangGuage/medal_1.png");
parameters.putString("name", "LangGuage");// name of link
parameters.putString("captions", "hello");
parameters.putString("message", "This is my message!!");

但我想将图像留给文本,但上面的代码给出的结果是消息下方的 Imgae。 更新:我无法从 json 中发布任何内容。任何人都可以解决这个问题,我想发送将图像和按摩与 json 绑定的附件。

【问题讨论】:

  • 发布你的 logcat 异常

标签: android json facebook post photo


【解决方案1】:

你可以尝试额外添加这个参数:

parameters.putString("message", "this is my message");

编辑:

你可以试试:

parameters.putString("link", "http://www.hunkatech.com");
parameters.putString("picture", "http://hwsdemos.com/LangGuage/medal_1.png");
parameters.putString("name", "LangGuage");// name of link
parameters.putString("captions", "hello");
parameters.putString("message", "This is my message!!");

【讨论】:

  • 只有消息是由不带图片的消息发布的。
  • 我已根据您的回答更新了我的问题。感谢您的帮助!!!+1 的帮助请查看更新并相应地回答。
  • AFAIK 这是 Facebook 帖子的默认格式,我们无法修改。
  • 所以你的意思是不能把图像放在从 android 到 facebook 的消息旁边,因为它在 iphone 中工作?
  • 如果在 iPhone 中可以,那么在 android 中当然也可以。如果我有什么我会告诉你的。
【解决方案2】:

这是我的做法。

private void publishFeedDialog() {
        System.out.println("Working");
        Bundle postParams = new Bundle();
        postParams.putString("name", "I am an Engineer");
        postParams.putString("caption",
                "Working very heard to make things work.");
        postParams
                .putString("description",
                        "This project is killing me, Still I am trying, and finally I got success.");
        postParams.putString("link", "http://www.kodebusters.com");
        postParams
                .putString(
                        "picture",
                        "http://cdn1.iconfinder.com/data/icons/iconslandsport/PNG/128x128/Soccer_Ball.png");

        new MYasync(postParams).execute();

    }

在 AsyncTask 上运行您的网络调用,否则它可能会通过异常

 class MYasync extends AsyncTask<Void, Void, Void> {

            Bundle params;
            private String res;

            public MYasync(Bundle params) {
                super();
                this.params = params;
            }

            @Override
            protected void onPostExecute(Void result) {
                System.out.println(res);
                super.onPostExecute(result);
            }

            @Override
            protected Void doInBackground(Void... pp) {
                try {
                    res = facebook.request("me/feed", params, "POST");

                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return null;
            }

        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 2020-10-01
    • 1970-01-01
    相关资源
    最近更新 更多