Android Facebook sdk 3.5 share dialog

2019-04-13 07:44发布

hi i am implementing the facebook share dialog for android sdk 3.5 however i am not getting any success im following the guides..

FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(MyClass.this)
                            .setApplicationName("App Name")
                            .setName("Name")
                            .setLink("mylink")
                            .build();

i put this inside my on touch method there are no errors appearing but whenever i click the button.. nothing appears also~

is the MyClass.this wrong? thanks for reply~

3条回答
唯我独甜
2楼-- · 2019-04-13 08:19

This is what Facebook recommends. I've just copied the code examples from this link where it is also explained how to handle the uiHelper instance.

If you don't care about the results of the dialog it might be ok not to use the uiHelper.

Using the static method to check whether the dialog can be presented is prudent because it only initializes the builder and creates the dialog if it really is possible to present it.

if (FacebookDialog.canPresentShareDialog(getApplicationContext(),
FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) {
    // Publish the post using the Share Dialog
    FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
            .setLink("https://developers.facebook.com/android")
            .build();
    uiHelper.trackPendingDialogCall(shareDialog.present());

} else {
    // Fallback. For example, publish the post using the Feed Dialog
    publishFeedDialog();
}

And this is the feed dialog fallback:

private void publishFeedDialog() {
    Bundle params = new Bundle();
    params.putString("name", "Facebook SDK for Android");
    params.putString("caption", "Build great social apps and get more installs.");
    params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
    params.putString("link", "https://developers.facebook.com/android");
    params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");

    WebDialog feedDialog = (
            new WebDialog.FeedDialogBuilder(getActivity(),
                    Session.getActiveSession(),
                    params)).build();
    feedDialog.show();
}
查看更多
太酷不给撩
3楼-- · 2019-04-13 08:34

I had this exact problem, it turned out I forgot to add <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> before the </application> tag in my AndroidManifest.xml.

查看更多
The star\"
4楼-- · 2019-04-13 08:38

Please look at this: This is a useful link https://gist.github.com/jacklt/6700201

查看更多
登录 后发表回答