How to integrate Facebook in my android application?

后端 未结 1 1921
暗喜
暗喜 2020-12-12 08:46

I am writing a code for facebook integration.I created App Id and also imported facebook sdk.I put a button on my main activity which will open up a facebook dialog asking l

相关标签:
1条回答
  • 2020-12-12 08:53

    Please go through this https://github.com/facebook/facebook-android-sdk/ and https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

    private OnClickListener loginButtonListener = new OnClickListener() {
        public void onClick(View v) {
            if (!mFacebook.isSessionValid()) {
                Toast.makeText(Login.this, "Authorizing", Toast.LENGTH_SHORT)
                        .show();
                mFacebook.authorize(Login.this, new String[] { "" },
                        new LoginDialogListener());
            } else {
                Toast.makeText(Login.this, "Has valid session",
                        Toast.LENGTH_SHORT).show();
                try {
                    JSONObject json = Util.parseJson(mFacebook.request("me"));
                    String facebookID = json.getString("id");
                    String firstName = json.getString("first_name");
                    String lastName = json.getString("last_name");
                    Toast.makeText(
                            Login.this,
                            "You already have a valid session, " + firstName
                                    + " " + lastName
                                    + ". No need to re-authorize.",
                            Toast.LENGTH_SHORT).show();
                } catch (Exception error) {
                    Toast.makeText(Login.this, error.toString(),
                            Toast.LENGTH_SHORT).show();
                } catch (FacebookError error) {
                    Toast.makeText(Login.this, error.toString(),
                            Toast.LENGTH_SHORT).show();
                }
            }
        }
    };
    
    0 讨论(0)
提交回复
热议问题