是否有可能从我的Andr​​oid应用程序共享多张照片和文字给Facebook? [英] Is it possible to share multiple photos and texts to Facebook from my Android app?

查看:763
本文介绍了是否有可能从我的Andr​​oid应用程序共享多张照片和文字给Facebook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给Facebook共享我的Andr​​oid应用程序集成。我有多个图像和文本4分享。所以我的问题是:


  1. 我可以使用意向用于此目的以外的其他使用Facebook的SDK?

  2. 我已经加入Facebook的图书馆,像 Android上的共享做了登录和简单共享样本。可我用这个对我的要求?

code:

  ShareButton shareButton =(ShareButton)findViewById(R.id.fb_share_button);    ShareOpenGraphObject对象=新ShareOpenGraphObject.Builder()
            .putString(OG:类型,books.book)
            .putString(OG:称号,权力的游戏)
            .putString(
                    OG:描述,
                    在冻结废物冬北,邪恶和超自然力量都卯足。)
            。.putString(书:ISBN,0-553-57340-3)建设();    位图位图= BitmapFactory.de codeResource(getResources()
            R.drawable.ic_launcher);
    SharePhoto照片=新SharePhoto.Builder()。setBitmap(位图)
            .setUserGenerated(真).build();    //创建一个动作
    ShareOpenGraphAction行动=新ShareOpenGraphAction.Builder()
            .setActionType(books.reads)。putObject(书,对象)
            .putPhoto(形象,照片).build();    //创建内容
    ShareOpenGraphContent内容=新ShareOpenGraphContent.Builder()
            .SET previewPropertyName(书)的setAction(动作).build();
    ShareDialog.show(MainActivity.this,内容);
    shareButton.setShareContent(内容);


解决方案

有关您需要添加照片放多个时间多张照片。假设你有3个要分享的图片。您需要实现以下code。

\r
\r

ShareOpenGraphAction行动=新ShareOpenGraphAction.Builder()\r
            .setActionType(books.reads)。putObject(书,对象)\r
            .putPhoto(形象,照片)\r
            .putPhoto(形象,照片)\r
            .putPhoto(形象,照片).build();

\r

\r
\r

您可以根据您的需要使这个code动态。它工作正常,我分享多张图片。

另外还有一个方法addPhotos SharePhotoContent ,我用低于code共享图像。我可以给列表与LT;> addPhotos 方式STRONG>。

\r
\r

私人无效publishImage(){\r
位图图像= BitmapFactory.de codeResource(getResources()\r
R.drawable.ic_launcher);\r
\r
    //你需要从任何来源获得的位图。\r
\r
SharePhoto照片=新SharePhoto.Builder()。setBitmap(图)\r
.setCaption(欢迎到Facebook的照片共享类固醇!)\r
.build();\r
\r
SharePhotoContent内容=新SharePhotoContent.Builder()。addPhoto(\r
照片).build();\r
\r
ShareApi.share(内容,NULL);\r
Toast.makeText(这一点,Succsesfully贴在墙上,\r
Toast.LENGTH_LONG).show();\r
\r
}

\r

\r
\r

I want to integrate Facebook sharing in my Android app. I have multiple images and 4 texts to share. So my question is:

  1. Can i use Intent for this purpose other than using Facebook SDK?
  2. I have added Facebook library and done a sample for login and simple sharing like mentioned in Sharing on Android.Can i use this for my requirement?

Code:

ShareButton shareButton = (ShareButton) findViewById(R.id.fb_share_button);

    ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "books.book")
            .putString("og:title", "A Game of Thrones")
            .putString(
                    "og:description",
                    "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
            .putString("books:isbn", "0-553-57340-3").build();

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.ic_launcher);
    SharePhoto photo = new SharePhoto.Builder().setBitmap(bitmap)
            .setUserGenerated(true).build();

    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("books.reads").putObject("book", object)
            .putPhoto("image", photo).build();

    // Create the content
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("book").setAction(action).build();
    ShareDialog.show(MainActivity.this, content);
    shareButton.setShareContent(content);

解决方案

For multiple photos you need to add put photos multiple time. Suppose you have 3 images to share. You need to implement following code.

ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("books.reads").putObject("book", object)
            .putPhoto("image", photo)
            .putPhoto("image", photo)
            .putPhoto("image", photo).build();

You can make this code dynamic according to your need. It works fine for me to share multiple images.

Also there is one method addPhotos in SharePhotoContent, I have used below code for sharing images. I am able to give List<> in addPhotos method.

private void publishImage() {
		Bitmap image = BitmapFactory.decodeResource(getResources(),
				R.drawable.ic_launcher);

    //You need to get bitmap from any source.

		SharePhoto photo = new SharePhoto.Builder().setBitmap(image)
				.setCaption("Welcome To Facebook Photo Sharing on steroids!")
				.build();

		SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(
				photo).build();

		ShareApi.share(content, null);
		Toast.makeText(this, "Succsesfully posted on your wall",
				Toast.LENGTH_LONG).show();

	}

这篇关于是否有可能从我的Andr​​oid应用程序共享多张照片和文字给Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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