gpt4 book ai didi

android - 分享媒体内容使用 facebook sdk 4.x+

转载 作者:太空狗 更新时间:2023-10-29 14:55:58 26 4
gpt4 key购买 nike

我举了一个关于在 android 中使用 facebook sdk 将我的状态(包括链接、照片、视频)发布到我的墙上的例子。按照这个 facebook 的教程链接:facebook startup tutorial我已经通过 ShareLinkContent 类成功登录并发布了链接状态。但是如果没有安装官方 android facebook 应用程序,我无法共享照片(SharePhotoContent 类)和视频(ShareVideoContent 类)。本教程不要求必须先安装他们的应用程序,但我无法使用我的示例应用程序在没有安装他们的应用程序的情况下发布我的照片、视频。

ShareDialog.canShow(ShareLinkContent.class)

无论安装了他们的 Facebook 应用程序,总是返回 true

ShareDialog.canShow(SharePhotoContent.class)
ShareDialog.canShow(ShareVideoContent.class)

只有安装了他们的 facebook 应用程序才返回 true

我分享照片的代码:

    public void sharePhoto() {
Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
SharePhoto photo = new SharePhoto.Builder().setBitmap(image).build();
SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(photo).build();
ShareDialog dialog = new ShareDialog(this);
if (ShareDialog.canShow(SharePhotoContent.class)){
dialog.show(content);
}
else{
Log.d("Activity", "you cannot share photos :(");
}
}

分享视频的代码:

   public void shareVideo() {
Uri selectedVideo = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Video" + "/fight.mp4");
if (ShareDialog.canShow(ShareVideoContent.class)) {
ShareVideo shareVideo = new ShareVideo.Builder().setLocalUrl(selectedVideo).build();
ShareVideoContent shareVideoContent = new ShareVideoContent.Builder()
.setVideo(shareVideo)
.setContentTitle("Video Title")
.setContentDescription("Video description")
.build();
ShareDialog dialog = new ShareDialog(this);
dialog.show(shareVideoContent);
} else{
Log.d("Activity", "you cannot share videos :(");
}
}

我已经设置了我的应用程序的权限:“publish_actions”。

我错过了什么吗?还是真的我必须先安装 facebook 应用程序,然后才能使用他们提供的 sdk(以防发布照片、视频)开发我的应用程序?

最佳答案

你初始化Facebook SDK了吗.......如果是,那么请求这样的许可

Set<String> permissions = AccessToken.getCurrentAccessToken()
.getPermissions();

final List<String> PUBLISH_PERMISSIONS = Arrays
.asList("publish_actions");
if (!permissions.containsAll(PUBLISH_PERMISSIONS)) {

// pendingPublishReauthorization = true;
LoginManager.getInstance().logInWithPublishPermissions(this,
PUBLISH_PERMISSIONS);
return;
}

然后检查你是否能够像这样发布网络图像......

 ShareLinkContent content1 = new ShareLinkContent.Builder()
.setContentUrl(
Uri.parse("https://play.google.com/store/apps/details?id=pk.wisesolutions.naatcollection"))
.setContentTitle(final_messgae)
.setContentDescription(
"Naat Collection App - listen to hundreds of naats free")
.setImageUrl(
Uri.parse("http://apps.wisesolutions.pk/app/naatcollection/images/logo_180x180.png"))
.build();

MessageDialog.show(mContext, content1);

关于android - 分享媒体内容使用 facebook sdk 4.x+,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31375657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com