使用setContentUrl()从Android在Facebook上共享 [英] Sharing on Facebook from Android using setContentUrl()

查看:194
本文介绍了使用setContentUrl()从Android在Facebook上共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试将我的应用程序中的内容共享到Facebook时遇到麻烦. 我正在使用以下代码来做到这一点:

I am having some trouble while trying to share content from my app into Facebook. I am using the following code to do it:

facebookButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(ShareDialog.canShow(ShareLinkContent.class)){
                ShareLinkContent linkContent=new ShareLinkContent.Builder()
                        .setContentUrl(Uri.parse(imageUrls.get(0)))
                        .build();
                shareDialog.show(linkContent, ShareDialog.Mode.WEB);

            }
        }
    });

我的图像存储在Firebase Storage上,也可以在Facebook上发布,但是标题和描述都设置为firebasestorage.googleapis.com,就像该链接的图像一样: 分享帖子的屏幕截图

My images are stored on Firebase Storage and I am able to post on Facebook as well but the title and description are both set to firebasestorage.googleapis.com like this linked image: screenshot of share post

注意:setContentDescription()和setContentTitle()和setImageUrl()均已弃用. 有没有一种方法可以设置共享帖子的标题和描述?

Note : The setContentDescription() and setContentTitle() and setImageUrl() are all deprecated. Is there a way to set the title,and description of the shared post?

推荐答案

FadyDev,我不知道您是否已经解决了问题,但这是我代替过时的代码所要做的事情:

FadyDev, I don't know if you've already resolved your problem but this is what I do in place of deprecated codes:

// Builds the object    
   ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("fb:app_id", my_app_ID)
            .putString("og:url", link_to_site)
            .putString("og:type", objectType)
            .putString("og:title", contentTitle)
            .putString("og:description", contentDescription)
            .putString("og:image", imageLink)
            .build();

// Builds the action
        ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                .setActionType(actionName)
                .putObject(objectName, object)
                .build();

// Create the openGraphContent
        ShareOpenGraphContent openGraphContent = new ShareOpenGraphContent.Builder()
                .setPreviewPropertyName(objectName)
                .setAction(action)
                .build();

        return openGraphContent;

在facebook文档中查找要使用的操作以及相应的对象类型和所需的参数.

Look in the facebook doc for what action you want to use and there corresponding object type and required parameters.

https://developers.facebook.com/docs/sharing/opengraph /using-actions https://developers.facebook.com/docs/reference/opengraph

希望这会有所帮助!

这篇关于使用setContentUrl()从Android在Facebook上共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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