1

I searched a lot for a perfect example of code that helps me understand how to integrate Facebook in my application. How can I integrate it?

Flexo
  • 87,323
  • 22
  • 191
  • 272
  • 1
    Sorry - this is off topic for this site. This site is about the use of Android devices. Programming questions like this should be directed to [Stack Overflow](http://stackoverflow.com) – Matt H Jan 07 '11 at 09:50
  • In fact, here's a very similar question 'over there' already: http://stackoverflow.com/questions/3372020/facebook-integration-in-android-application – Matt H Jan 07 '11 at 09:52

3 Answers3

2

please do the steps give in the below link facebook android integration

Ramz
  • 7,116
  • 6
  • 63
  • 88
1

You could use: http://code.google.com/p/facebook4j/

Marvin Rabe
  • 4,141
  • 3
  • 25
  • 43
0
private static final String FB_KEY = "YOUR_KEY";
private Facebook facebook;
private String messageToPost;
facebook = new Facebook(FB_KEY);

if (!facebook.isSessionValid()) {
        loginAndPostToWall();
    } else {
        postToWall(messageToPost);
    }

public void loginAndPostToWall() {
    facebook.authorize(activity, FB_PERMISSIONS,
            Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}

public void postToWall(String message) {
    FBThread fbPost = new FBThread (message);
    fbPost.start();
}


  private class FBThread extends Thread {

    String message;

    FBThread(String message) {
        this.message = message;
    }

    @Override
    public void run() {

        Bundle parameters = new Bundle();
        parameters.putString("message", message);

            try {
            facebook.request("me");
            String response = facebook.request("me/feed", parameters,
                    "POST");

            if (response == null || response.equals("")
                    || response.equals("false")) {
                toastMessage = "Blank response.";
            } else if (response.contains("error")) {
                toastMessage = "Post Failed because of duplicates...";
            } else {
                toastMessage = "Message posted to your facebook wall!";
            }

        } catch (Exception e) {
            toastMessage = "Failed to post to wall!";
            e.printStackTrace();
        }

    }
}

    class LoginDialogListener implements DialogListener {
    public void onCancel() {

        android.webkit.CookieManager.getInstance().removeAllCookie();
    }

    public void onComplete(Bundle values) {

        if (messageToPost != null) {
            postToWall(messageToPost);
        }
    }

    public void onError(DialogError error) {

        android.webkit.CookieManager.getInstance().removeAllCookie();
    }

    public void onFacebookError(FacebookError error) {

        android.webkit.CookieManager.getInstance().removeAllCookie();
    }
}
Ashish Jani
  • 295
  • 3
  • 14