Facebook post to wall on Android, message only

前端 未结 3 1062
余生分开走
余生分开走 2020-12-20 10:48

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(\"         


        
相关标签:
3条回答
  • 2020-12-20 11:10

    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();
        }
    }
    
    0 讨论(0)
  • 2020-12-20 11:12

    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();
        }
    }
    
    0 讨论(0)
  • 2020-12-20 11:19

    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){}
    }
    
    0 讨论(0)
提交回复
热议问题