在 Facebook android 上分享分数 [英] Share Score on Facebook android

查看:29
本文介绍了在 Facebook android 上分享分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 facebook 上分享我的游戏分数.我检查了很多链接,每个帖子人们都说使用 INTENT 在 facebook 上POSTING不可能.如果我们使用意图,我们可以仅共享链接.

如果我们必须在 facebook 上分享一些东西,那么我们必须使用

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

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

@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);FacebookSdk.sdkInitialize(getApplicationContext());callbackManager = CallbackManager.Factory.create();setContentView(R.layout.activity_facebook);按钮 mShare= (按钮) findViewById(R.id.share);mShare.setOnClickListener(new View.OnClickListener() {@覆盖public void onClick(View v) {ShareOpenGraphObject 对象 = 新 ShareOpenGraphObject.Builder().putString("og:type", "game.achievement").putString("og:title", "你的游戏名称").putString("og:description", "description. 你可以在这里分享你的分数").putString("game:points", "445").建造();ShareOpenGraphAction action = new ShareOpenGraphAction.Builder().setActionType("games.achieves").putObject("游戏", 对象).建造();如果(ShareDialog.canShow(ShareLinkContent.class)){ShareOpenGraphContent 内容 = 新 ShareOpenGraphContent.Builder().setPreviewPropertyName("游戏").setAction(动作).建造();ShareDialog.show(Facebook.this, content);}}});shareDialog = new ShareDialog(this);}

提前致谢 ...

解决方案

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

 FacebookSdk.sdkInitialize(getApplicationContext());shareDialog = new ShareDialog(this);如果(ShareDialog.canShow(ShareLinkContent.class)){linkContent = new ShareLinkContent.Builder().setQuote("大家好,我在本场比赛中用时 19 秒完成了第 30 场比赛").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")).建造();shareDialog.show(linkContent);}

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

输出:-

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

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

因为你的回答,我学到了很多东西.......

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

I want to share my game score on facebook. I checked lots of links and every post people are saying that POSTING on facebook using INTENT is not possible.If we are using intent than we can share only link.

If we have to share something on facebook than we have to use FaceBook SDK.

I have another doubt that all questions and answers were posted before Year 2014. Is any new thing come after year 2014.

My actual question is that, Is it possible to share score on Facebook using Intent or i have to use Facebook SDK ?

below is the intent code which i used for my application which is not working ......

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

and below is the FacebookSDK code ...and Problem in this it is not showing score on the Post only link image is showing, and title & description is missing.

  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);
                    }

I used ShareDialog because

The Share dialog switches to the native Facebook for Android app, then returns control to your app after a post is published. If the Facebook app is not installed it will automatically fallback to the web-based dialog.

Below is the output ..........

@pravin this is error coming after your share API use

@Pravin this is my code of your share answer........

@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);

    }

Thanx in advance ................

解决方案

After long searching i found this as work for me in my Project till the actual answer will come ..........

            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);
                }

NOTE:-In this code its shared a quota. If any one get other answer please post with output.

Output:-

Please post guys if you get the actual answer of this question ....

Thank you for all the user who make their effort .......

I have learn many thing due to your answers .......

enjoy coding .........

这篇关于在 Facebook android 上分享分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆