在 android 上将图像和文本分享到 Facebook

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23787429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:27:08  来源:igfitidea点击:

Share Image and Text to Facebook on android

androidfacebookfacebook-sdk-3.14.x

提问by Iain Smith

What is the correct way to share an image and text to Facebook in android? e.g. picture with pre-populated text.

在android中将图像和文本共享到Facebook的正确方法是什么?例如带有预填充文本的图片。

I realise that this is not possible from the native Android share intent as described here. As it can only take an image or a link not both.

我意识到这是不可能从这里描述的本机 Android 共享意图中实现的。因为它只能拍摄图像或链接,不能同时拍摄。

Also I have tried using the facebook-sdk-3.14 with:

我也尝试过使用 facebook-sdk-3.14:

    FacebookDialog.ShareDialogBuilder 

but I now realise this is for sharing links only.

但我现在意识到这仅用于共享链接。

I have also tried with:

我也试过:

    createShareDialogBuilderForPhoto() 

but this is for sharing images only.

但这仅用于共享图像。

Is there something I am missing in the sdk? I am guessing it is not possible from FacebookDialog?

我在sdk中缺少什么吗?我猜 FacebookDialog 不可能?

Will I need to go the route of creating my own app in facebook and my own open graph action? Ideally I am looking to not have a login button.

我是否需要走在 Facebook 中创建自己的应用程序和我自己的开放图形操作的路线?理想情况下,我希望没有登录按钮

I have also seen similar questions but most are about the share intent or if it is the sdk it at least a year out of date and the solution is some thing similar to this:

我也看到过类似的问题,但大多数是关于共享意图的,或者如果它是 sdk,它至少已经过时了一年,并且解决方案与此类似:

    Bundle parameters = new Bundle();
            parameters.putString("message", category_item_name_desc.getText().toString());
            parameters.putString("picture", categoryItemsModel.getImageUrl());
            parameters.putString("caption", txtDescription_desc.getText().toString());
            facebook.request("/me/feed", parameters, "POST");

Tried it through the Feed Dialog (WebDialog) but im getting a "error (#324) requires upload file", Any help would be great.

通过 Feed Dialog (WebDialog) 尝试过,但我收到“错误 (#324) 需要上传文件”,任何帮助都会很棒。

采纳答案by Iain Smith

Was able to do this my self with the current Facebook SDK (3.14.1 at the time) with no login and I made it into a share intent for adding to the chooser list.

能够在没有登录的情况下使用当前的 Facebook SDK(当时为 3.14.1)自行完成此操作,并且我将其设置为添加到选择器列表的共享意图。

I have a demo project at https://github.com/b099l3/FacebookImageShareIntentonly dependency is the facebook sdk and it is contained in one activity.

我在https://github.com/b099l3/FacebookImageShareIntent有一个演示项目,唯一的依赖是 facebook sdk,它包含在一个活动中。

回答by Deepshikha Puri

You can share your image on facebook, Twitter, and Gmail:

您可以在 Facebook、Twitter 和 Gmail 上分享您的图片:

Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);

Intent share = new Intent(Intent.ACTION_SEND);

share.setType(“image/jpeg”);

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, “Title”, null);
Uri imageUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, “Select”));

回答by Anton Krasov

Please take a look a look on my library: https://github.com/antonkrasov/AndroidSocialNetworks

请看看我的图书馆:https: //github.com/antonkrasov/AndroidSocialNetworks

With help of it, posting is really easy:

有了它的帮助,发布真的很容易:

mSocialNetworkManager.getFacebookSocialNetwork().postMessage(String message)
mSocialNetworkManager.getFacebookSocialNetwork().postPhoto(File path...)