简体   繁体   English

Android Facebook SDK之类的按钮显示为灰色(不可点击)

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

I have a Fb login, share and like button in my app. 我的应用程序中有一个Fb登录,共享和赞按钮。 All are widgets from facebook sdk. 所有都是来自facebook sdk的小部件。 So by default they have facebook sdk's property. 因此,默认情况下,它们具有facebook sdk的属性。 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 . 我遵循了教程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. Facebook将不再支持“本地赞”按钮。 From a Facebook blog post : Facebook博客文章中

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. Native Like Button:专为移动应用程序设计的Native Like Button,从Facebook SDK 4.28及更高版本开始将不再受支持。 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. 早期版本的SDK仍可以使用“本机喜欢的按钮”,但是从2/6开始,将不再支持“本机喜欢的按钮”。 After 2/6, the dialogs for Native Like will no longer appear and taps on any native like button will result in no action. 2/6之后,将不再显示“本机喜欢”对话框,并且点击任何本机“喜欢”按钮将不会执行任何操作。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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