Android 上的 Facebook 帖子到墙,仅限消息

发布于 2024-12-08 21:58:04 字数 706 浏览 0 评论 0原文

下面的代码似乎只发布“消息”而没有其他内容。我有什么遗漏的吗? (使用 Facebook Android SDK)

parameters.putString("link", link);
parameters.putString("description", description);
parameters.putString("caption", caption);
parameters.putString("name", name);
parameters.putString("message", msg);

try {
    String response = mFacebook.request("me/feed", parameters, "POST");
} catch (IOException e) {
    Log.e("Error", e.toString());
}

我收到很多警告,但已阅读这是正常的(另外,我收到“消息”警告,但仍然发布:

Key caption expected byte[] but value was a java.lang.String.  The default value <null> was returned.
Attempt to cast generated internal exception:
java.lang.ClassCastException: java.lang.String

The below code only seems to POST the 'message' and nothing else. Is there something I am missing? (using the Facebook Android SDK)

parameters.putString("link", link);
parameters.putString("description", description);
parameters.putString("caption", caption);
parameters.putString("name", name);
parameters.putString("message", msg);

try {
    String response = mFacebook.request("me/feed", parameters, "POST");
} catch (IOException e) {
    Log.e("Error", e.toString());
}

I am getting lots of warnings but have read this is normal (also, I am getting a warning for 'message' but that still posts:

Key caption expected byte[] but value was a java.lang.String.  The default value <null> was returned.
Attempt to cast generated internal exception:
java.lang.ClassCastException: java.lang.String

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

子栖 2024-12-15 21:58:04

检查我编辑的答案,它将发布在用户的墙上:

它将显示异常情况,但不用担心,你的帖子将会成功。

public void postOnWall() {
    try{
        Bundle parameters = new Bundle();
        parameters.putString("message", "Text is lame. Listen up:");
        parameters.putString("name", "Name");
        parameters.putString("link", "http://www.google.com");
        parameters.putString("caption", "Caption");
        parameters.putString("description", "Description");

        String  response = facebook.request("me/feed",parameters,"POST");
        Log.v("response", response);
    }
    catch(Exception e){}
}

Check my edited answer, it will post on the user's wall:

It will show the exception case, but don't bother about it, your post will be succeed.

public void postOnWall() {
    try{
        Bundle parameters = new Bundle();
        parameters.putString("message", "Text is lame. Listen up:");
        parameters.putString("name", "Name");
        parameters.putString("link", "http://www.google.com");
        parameters.putString("caption", "Caption");
        parameters.putString("description", "Description");

        String  response = facebook.request("me/feed",parameters,"POST");
        Log.v("response", response);
    }
    catch(Exception e){}
}
浅听莫相离 2024-12-15 21:58:04

请参阅下面的代码。它正在运行代码。尝试一次。

public void postOnWall(String msg) {
    Log.d("Tests", "Testing graph API wall post");
    try {
        String response = facebook.request("me");
        Bundle parameters = new Bundle();
        parameters.putString("message", msg);
        parameters.putString("description", "test test test");
        response = facebook.request("me/feed", parameters,
                "POST");
        Log.d("Tests", "got response: " + response);
        if (response == null || response.equals("") ||
                response.equals("false")) {
           Log.v("Error", "Blank response");
        }
    } 
    catch(Exception e) {
        e.printStackTrace();
    }
}

See the below code. It's running code. Try it once.

public void postOnWall(String msg) {
    Log.d("Tests", "Testing graph API wall post");
    try {
        String response = facebook.request("me");
        Bundle parameters = new Bundle();
        parameters.putString("message", msg);
        parameters.putString("description", "test test test");
        response = facebook.request("me/feed", parameters,
                "POST");
        Log.d("Tests", "got response: " + response);
        if (response == null || response.equals("") ||
                response.equals("false")) {
           Log.v("Error", "Blank response");
        }
    } 
    catch(Exception e) {
        e.printStackTrace();
    }
}
暖伴 2024-12-15 21:58:04

试试这个它将与身份验证对话框一起使用

     private static final String[] PERMISSIONS =
           new String[] {"publish_stream", "read_stream", "offline_access"};


  Facebook authenticatedFacebook = new Facebook(APP_ID);


   postButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            authenticatedFacebook.authorize(Tests.this, PERMISSIONS,
                    new TestPostListener());
        }
    });


 public class TestPostListener implements DialogListener {

    public void onComplete(Bundle values) {
         try {
             Log.d("Tests", "Testing request for 'me'");
             String response = authenticatedFacebook.request("me");
             JSONObject obj = Util.parseJson(response);

             Log.d("Tests", "Testing graph API wall post");
             Bundle parameters = new Bundle();
             parameters.putString("message", "Amit Siddhpura");
             parameters.putString("description", "Hi Mr. Amit Siddhpura");
             response = authenticatedFacebook.request("me/feed", parameters, 
                     "POST");
             Log.d("Tests", "got response: " + response);
         } catch (Throwable e) {
             e.printStackTrace();
         }
    }

    public void onCancel() {
    }

    public void onError(DialogError e) {
        e.printStackTrace();
    }

    public void onFacebookError(FacebookError e) {
        e.printStackTrace();
    }
}

try this it will work with authentication dialog box

     private static final String[] PERMISSIONS =
           new String[] {"publish_stream", "read_stream", "offline_access"};


  Facebook authenticatedFacebook = new Facebook(APP_ID);


   postButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            authenticatedFacebook.authorize(Tests.this, PERMISSIONS,
                    new TestPostListener());
        }
    });


 public class TestPostListener implements DialogListener {

    public void onComplete(Bundle values) {
         try {
             Log.d("Tests", "Testing request for 'me'");
             String response = authenticatedFacebook.request("me");
             JSONObject obj = Util.parseJson(response);

             Log.d("Tests", "Testing graph API wall post");
             Bundle parameters = new Bundle();
             parameters.putString("message", "Amit Siddhpura");
             parameters.putString("description", "Hi Mr. Amit Siddhpura");
             response = authenticatedFacebook.request("me/feed", parameters, 
                     "POST");
             Log.d("Tests", "got response: " + response);
         } catch (Throwable e) {
             e.printStackTrace();
         }
    }

    public void onCancel() {
    }

    public void onError(DialogError e) {
        e.printStackTrace();
    }

    public void onFacebookError(FacebookError e) {
        e.printStackTrace();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文