简体   繁体   中英

Android Facebook SDK like button is greyed out (not clickable)

I have a Fb login, share and like button in my app. All are widgets from facebook sdk. So by default they have facebook sdk's property. As user want to share or like, (while not logged in), it will ask for login. then the action will be performed. I followed the tutorial https://developers.facebook.com .

Its working fine for login and share button, but like button is greyed out (not clickable). Any help to resolve this issue.

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageButton playBtn, someBtn;
    LoginButton loginButton;
    LikeView likeViewButton;
    ShareButton shareButton;
    ShareLinkContent linkContent;
    CallbackManager callbackManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initInstances();
        initCallbackManager();

        shareButton = (ShareButton)findViewById(R.id.share_button);
        linkContent = new ShareLinkContent.Builder().setContentUrl(Uri.parse("https://developers.facebook.com")).build();
        shareButton.setShareContent(linkContent);

        likeViewButton = (LikeView) findViewById(R.id.likeView_button);
        likeViewButton.setObjectIdAndType("http://inthecheesefactory.com/blog/understand-android-activty-launchmode/en", LikeView.ObjectType.PAGE);
    }

    private void initInstances() {
        playBtn = (ImageButton) findViewById(R.id.playBtn);
        playBtn.setOnClickListener(this);

        someBtn = (ImageButton) findViewById(R.id.someBtn);
        someBtn.setOnClickListener(this);

        loginButton = (LoginButton) findViewById(R.id.login_button);
        loginButton.setReadPermissions("public_profile");
    }

    private void initCallbackManager() {
        callbackManager = CallbackManager.Factory.create();
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                Log.d("Getting User Details", "Success");
                getUserDetails(loginResult);
            }

            @Override
            public void onCancel() {
                Log.d("LOGIN_CANCEL", "Cancel");
            }

            @Override
            public void onError(FacebookException error) {
                Log.d("LOGIN_ERROR", "Error");
            }
        });
    }
}

Facebook will no longer support the Native Like Button. From a Facebook blog post :

Native Like Button: The Native Like Button, designed for mobile apps, will no longer be supported starting with Facebook SDK version 4.28 and above. Previous versions of the SDK can still use the Native Like Button, but starting 2/6, the Native Like Button will no longer be supported. After 2/6, the dialogs for Native Like will no longer appear and taps on any native like button will result in no action.

如果您真的需要Like View,只需在build.gradle(应用程序)中编写此代码,但就不会再更新Facebook SDK

implementation 'com.facebook.android:facebook-android-sdk:4.27.0'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM