Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post on Facebook wall using Facebook Android SDK without opening dialog box

Using the Facebook SDK, I can login and store my access_token into a database. When I try to create a post, the Facebook wall is still empty on both my phone and emulator due to these problems:

1) I fetch an access_token from the database and pass the access_token to Facebook, but I'm not allowed to post on a wall.

2) I cannot post my message without opening a dialog box.

   mPostButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                String message = "Post this to my wall";

                Bundle params = new Bundle();             

                params.putString("message", message);

                mAsyncRunner.request("me/feed", params, "POST", new WallPostRequestListener());

            }
        });

 public class WallPostRequestListener extends BaseRequestListener {

        public void onComplete(final String response) {
            Log.d("Facebook-Example", "Got response: " + response);
            String message = "<empty>";
            try {
                JSONObject json = Util.parseJson(response);
                message = json.getString("message");
            } catch (JSONException e) {
                Log.w("Facebook-Example", "JSON Error in response");
            } catch (FacebookError e) {
                Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
            }
            final String text = "Your Wall Post: " + message;
            Example.this.runOnUiThread(new Runnable() {
                public void run() {
                    mText.setText(text);
                }
            });
        }
    }

How can I post to Facebook without opening the dialog box?

like image 759
Ankit Avatar asked Nov 18 '10 10:11

Ankit


2 Answers

i applied following code and could successfully posted my message on wall.

public void postOnWall(String msg) {
        Log.d("Tests", "Testing graph API wall post");
         try {
                String response = mFacebook.request("me");
                Bundle parameters = new Bundle();
                parameters.putString("message", msg);
                parameters.putString("description", "test test test");
                response = mFacebook.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();
         }
    }
like image 85
Ankit Avatar answered Sep 20 '22 09:09

Ankit


I updated my tutorial at http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/ and it is now exactly answering this question. It is based on and basically the same as Ankit's answer, but guides people from start to finish through implementing the whole process.

like image 28
Integrating Stuff Avatar answered Sep 18 '22 09:09

Integrating Stuff