在Facebook上分享得分android

sus*_*dlh 20 android facebook android-intent

我想在Facebook上分享我的游戏分数.我查了很多环节,每一个岗位的人说,POSTING上使用Facebook的意向不可能的.如果我们使用的意图不是我们可以共享的唯一联系.

如果我们必须在Facebook分享一些东西,那么我们必须使用FaceBook SDK.

我怀疑所有的问题和答案是在2014年之前发布的.2014年之后是否有新事物发生.

我的实际问题是,是否有可能使用Intent在Facebook上分享分数,或者我必须使用Facebook SDK

下面是我用于我的应用程序的意图代码,它不起作用......

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT, message);
        startActivity(Intent.createChooser(intent, "Share on"));
Run Code Online (Sandbox Code Playgroud)

以下是FacebookSDK代码...并且问题在于它没有显示发布链接图像上的分数,并且缺少标题和描述.

  FacebookSdk.sdkInitialize(getApplicationContext());

            shareDialog = new ShareDialog(this);
             if (ShareDialog.canShow(ShareLinkContent.class)) {
                        linkContent = new ShareLinkContent.Builder()
                                .setContentTitle(title)
                                .setContentDescription(description)
                                .setContentUrl(Uri.parse(link)).
                                .setImageUrl(Uri.parse(imageLink)   
                                .build();

                        shareDialog.show(linkContent);
                    }
Run Code Online (Sandbox Code Playgroud)

我使用ShareDialog是因为

"共享"对话框切换到原生Facebook for Android应用程序,然后在发布帖子后将控制权返回给您的应用程序.如果未安装Facebook应用程序,它将自动回退到基于Web的对话框.

以下是输出..........

产量

@pravin这是您使用共享API后出现的错误

Ø

@Pravin这是我的代码答案........

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();

        setContentView(R.layout.activity_facebook);

        Button mShare= (Button) findViewById(R.id.share);

        mShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
                        .putString("og:type", "game.achievement")
                        .putString("og:title", "Name of your game")
                        .putString("og:description", "description. You can share your score here")
                        .putString("game:points", "445")
                        .build();

                ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                        .setActionType("games.achieves")
                        .putObject("game", object)
                        .build();




                if (ShareDialog.canShow(ShareLinkContent.class)) {
                    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
                            .setPreviewPropertyName("game")
                            .setAction(action)
                            .build();

                    ShareDialog.show(Facebook.this, content);
                }
            }
        });
        shareDialog = new ShareDialog(this);

    }
Run Code Online (Sandbox Code Playgroud)

Thanx提前................

sus*_*dlh 8

经过长时间的搜索,我发现这在我的项目中对我有用,直到实际的答案来了..........

            FacebookSdk.sdkInitialize(getApplicationContext());

            shareDialog = new ShareDialog(this);
            if (ShareDialog.canShow(ShareLinkContent.class)) {
                    linkContent = new ShareLinkContent.Builder()
                        .setQuote("Hi Guys I have completed Game 30 in 19 seconds  in this game")
                        .setImageUrl(Uri.parse("https://lh3.googleusercontent.com/jUej7mN6M6iulmuwmW6Mk28PrzXgl-Ebn-MpTmkmwtOfj5f0hvnuw8j0NEzK0GuKoDE=w300-rw"))
                        .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.mobtraffiq.numbertap&hl=en"))
                        .build();

                    shareDialog.show(linkContent);
                }
Run Code Online (Sandbox Code Playgroud)

注意: - 在此代码中,它共享一个配额.如果有人得到其他答案请发布输出.

输出: -

产量

如果你得到这个问题的实际答案,请发帖.

感谢所有努力的用户.......

由于你的答案我学到了很多东西.......

享受编码.........


小智 0

我相信Facebook SDK使用后台Activity来进行实际的数据传输,但您仍然需要制作自己的Activity及其布局,这里的示例向展示如何创建自己的共享和登录工具