0

我正在尝试在我的应用程序中使用共享按钮,但它看起来好像被禁用了:

禁用共享按钮

我已经初始化了sdk:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(getApplicationContext());
}

我还按照文档建议正确配置了清单: https ://developers.facebook.com/docs/android/getting-started

视图中的按钮是这样的:

<com.facebook.share.widget.ShareButton
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/share"
              android:id="@+id/share_on_fb_button"
              bind:onClick="shareOnFBButtonClick"/>

可能是什么问题呢?为什么按钮被禁用?我应该在我的应用程序中实现登录功能吗?或者我只需要在设备上安装 facebook 应用程序?

4

1 回答 1

3

请参阅 com.facebook.share.widget.ShareButtonBase:

/**
 * Sets the share content on the button.
 * @param shareContent The share content.
 */
public void setShareContent(final ShareContent shareContent) {
    this.shareContent = shareContent;
    if (!enabledExplicitlySet) {
        internalSetEnabled(canShare());
    }
}

调用 setShareContent 启用 shareButton,试试看:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);

    ShareButton fbShareButton = (ShareButton) findViewById(R.id.share_on_fb_button);
    ShareLinkContent content = new ShareLinkContent.Builder()
            .setContentUrl(Uri.parse("https://developers.facebook.com"))
            .build();
    fbShareButton.setShareContent(content);
}

注意: https ://developers.facebook.com/docs/sharing/android

“当你实现分享时,你的应用不应该预先填充任何要分享的内容。这与 Facebook 平台政策不一致,请参阅 Facebook 平台政策,2.3。”

于 2015-10-18T15:38:34.633 回答