简体   繁体   English

Facebook在Android上发布到墙上,仅消息

[英]Facebook post to wall on Android, message only

The below code only seems to POST the 'message' and nothing else. 下面的代码似乎只发布了“消息”,仅此而已。 Is there something I am missing? 我有什么想念的吗? (using the Facebook Android SDK) (使用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

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){}
}

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();
    }
}

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM