Android Facebook分享未在Facebook墙上显示说明

时间:2015-02-03 12:25:34

标签: java android facebook-android-sdk

当我的应用尝试共享内容时,说明会显示在共享活动中,但在发布时不会显示。我经历了很多stackoverflow帖子,但没有什么能解决我的问题。

这是我的通话流程:

  1. 点击分享按钮
  2. Activity调用静态方法并传递自身和内容以通过Bundle
  3. 与其共享
  4. 从此静态方法调用共享活动。它显示要与所有图像,标题和说明正确共享的内容
  5. 内容已成功共享
  6. 当Facebook帖子被选中时,它只显示Playstore应用程序的详细信息,我在3中设置的图像没有描述
  7. 以下是我使用的代码

    if (FacebookDialog.canPresentShareDialog(activity.getApplicationContext(), 
         FacebookDialog.ShareDialogFeature.SHARE_DIALOG)) 
        {
         FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(activity)
               .setLink("<playstore link>")
               .setApplicationName("<appname>")
               .setName("<some name>")
               .setCaption("<some text>")
               .setDescription("a description")
               .setPicture("http://url/to/image.jpg")
               .build();
            uiHelper.trackPendingDialogCall(shareDialog.present());
        }
    

    但使用FeedDialog共享相同的工作

    Bundle params = new Bundle();
                        params.putString("name", "name");
                        params.putString("caption", "caption");
                        params.putString("description","desc");
                        params.putString("link", "playstore link");
                        params.putString("picture", "http://url/to/image.jpg");
    
                        WebDialog feedDialog = (
                            new WebDialog.FeedDialogBuilder(activity,
                                    session,
                                params))
                            .setOnCompleteListener(new OnCompleteListener() {
    
                                @Override
                                public void onComplete(Bundle values,
                                    FacebookException error) {
                                    if (error == null) {
    
                                        final String postId = values.getString("post_id");
                                        if (postId != null) {
                                            Toast.makeText(activity,
    
                                                "Posted Successfully!",
                                                Toast.LENGTH_SHORT).show();
                                            activity.finish();
                                        } else {
                                            // User clicked the Cancel button
                                            Toast.makeText(activity.getApplicationContext(), 
                                                "Publish cancelled", 
                                                Toast.LENGTH_SHORT).show();
    
                                            activity.finish();
                                        }
                                    } else if (error instanceof FacebookOperationCanceledException) {
                                        // User clicked the "x" button
                                        Toast.makeText(activity.getApplicationContext(), 
                                            "Publish cancelled", 
                                            Toast.LENGTH_SHORT).show();
                                        activity.finish();
                                    } else {
    
                                        Toast.makeText(activity.getApplicationContext(), 
                                            "An Error Occurred", 
                                            Toast.LENGTH_SHORT).show();
                                        activity.finish();
                                    }
    
    
                                }
    
    
    
                            })
                            .build();
                        feedDialog.show();
    

    谢谢

2 个答案:

答案 0 :(得分:1)

来自docs(版本4.0 +)

  

要显示活动中链接的ShareDialog,请创建一个   onCreate方法中的ShareDialog实例:

public class MainActivity extends FragmentActivity {
    CallbackManager callbackManager;
    ShareDialog shareDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();
        shareDialog = new ShareDialog(this);
        // this part is optional
        shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() { ... });
    }
     

然后显示ShareDialog:

if (ShareDialog.canShow(ShareLinkContent.class)) {
    ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentTitle("Hello Facebook")
            .setContentDescription(
                    "The 'Hello Facebook' sample  showcases simple Facebook integration")
            .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
            .build();

    shareDialog.show(linkContent);
}

答案 1 :(得分:0)

Slartibartfast的答案工作正常,直到compile 'com.facebook.android:facebook-android-sdk:4.24.0'

来自Facebook SDK版本4.25.0

setContentTitle("") setContentDescription("")已被删除。 您必须使用setQuote("");方法而不是setContentDescription("");

有关折旧的详细信息,请参阅:https://developers.facebook.com/docs/sharing/android