首页 > 解决方案 > Facebook 分享对话框未显示 - Android Facebook API

问题描述

单击 facebook 分享按钮后,分享对话框出现并立即消失。在shareDialog.registerCallback它转到onError方法中。不明白为什么会这样。

CallbackManager callbackManager;
    ShareDialog shareDialog;

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
FacebookSdk.setApplicationId(String.valueOf(R.string.facebook_app_id));
        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();
        shareDialog = new ShareDialog(this);

shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {
                Toast.makeText(MainActivity.this, "onSuccess", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onCancel() {
                Toast.makeText(MainActivity.this, "onCancel", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(FacebookException error) {
                Toast.makeText(MainActivity.this, "Opps! Some error occurred. Please try again", Toast.LENGTH_SHORT).show();
            }
        });

bFbShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (ShareDialog.canShow(ShareLinkContent.class)) {
                    ShareLinkContent linkContent = new ShareLinkContent.Builder()
                      .setQuote("Hi ABCE")                     .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName()))
                            .build();
                    shareDialog.show(MainActivity.this, linkContent);
                }
            }
        });

Logcat我得到这个

GraphResponse: {HttpStatus: 404, errorCode: 803, subErrorCode: -1, errorType: OAuthException, errorMessage: (#803) Some of the aliases you requested do not exist: 2131492917}

标签: androidandroid-facebook

解决方案


为我工作if (ShareDialog.canShow(ShareLinkContent.class))onClick


推荐阅读