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

时间:2017-10-21 14:06:31

标签: android facebook-graph-api facebook-like

我的应用中有一个Fb登录,分享和喜欢按钮。所有这些都是来自facebook sdk的小部件。所以默认情况下他们有facebook sdk的属性。当用户想要分享或喜欢(虽然没有登录)时,它会要求登录。然后将执行该操作。我按照教程https://developers.facebook.com

它适用于登录和分享按钮,但之类的按钮显示为灰色(无法点击)。有任何帮助来解决此问题。

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");
            }
        });
    }
}

2 个答案:

答案 0 :(得分:0)

Facebook将不再支持Native Like Button。来自Facebook blog post

Native Like按钮:从Facebook SDK版本4.28及更高版本开始,将不再支持专为移动应用程序设计的Native Like按钮。以前版本的SDK仍然可以使用Native Like按钮,但从2/6开始,将不再支持Native Like按钮。在2/6之后,Native Like的对话框将不再出现,点击任何原生的按钮将导致无法执行操作。

答案 1 :(得分:0)

如果你真的需要Like View,只需在build.gradle(app)中编写,但你不会再更新Facebook SDK了

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