-1

下面的代码似乎只发布“消息”,没有别的。有什么我想念的吗?(使用 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
4

3 回答 3

7

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

它会显示异常情况,但不要理会它,你的帖子会成功的。

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){}
}
于 2011-10-10T12:01:12.727 回答
0

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

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();
    }
}
于 2011-10-10T12:20:35.440 回答
0

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

     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();
    }
}
于 2012-08-25T13:55:15.367 回答