后的图像文本从Facebook的Andr​​oid版图像、文本、Facebook、Andr

2023-09-07 10:21:50 作者:拾取

我怎么可以张贴在Facebook上的文字图片?我知道如何发布文本,链接,但我想张贴图片为好。

下面是我曾尝试:

 字节[]数据= NULL; 位图双= BitmapFactory.de codeFILE(R.drawable.plate1); ByteArrayOutputStream BAOS =新ByteArrayOutputStream(); bi.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS); 数据= baos.toByteArray(); parameters.putByteArray(图片,数据); INT板= getResources()则getIdentifier(com.b2creativedesigns.eyetest:绘/ plate1,NULL,NULL); parameters.putString(图片,将String.valueOf(板)); 

他们都没有工作。当我尝试后,没有任何反应。没有张贴。与下面的code,它的工作原理。

从网站上公布的图像是很容易的,但它不会工作,当网站得到关机或修改的链接。

  parameters.putString(图片,https://m.xsw88.com/allimgs/daicuo/20230907/5063.png.JPEG,100,BAOS);  数据= baos.toByteArray();  parameters.putString(法,photos.upload);  parameters.putByteArray(图片,数据); 

解决方案

编辑:对不起,我不应该对如何,因为它是pcated德$ P $使用REST API的建议。这是您使用图形API如何将照片上传到自己的墙壁上。

 捆绑PARAMS =新包();params.putByteArray(照片的数据);params.putString(标题,测试照片上传);    mAsyncRunner.request(ME /照片,则params,POST,    新PhotoUploadListener(),NULL); 

请尝试这一点,看看它是否工作。这是直接取出我们HackBook例如我们的文档中获得。对于图像的COM pression,您可以使用我们的 Utility.scaleImage 我们的SDK里面的方法,该方法将完成所有的COM pression和缩放以满足Facebook的标准。

=============================================== ===================================

原始消息:

photos.upload 使用REST API,是pcated所以去$ P $我会建议使用的图形API来上传照片,但这里是用快速和肮脏的解决方案在REST API。

一旦你有一个变量的字节数组,如数据,请执行以下操作:

 捆绑PARAMS =新包();params.putString(法,photos.upload);params.putByteArray(图片,数据);mFacebook.request(PARAMS); 

让我知道是否有帮助。

How can I post an image with text on facebook? I know how to post text, links, but I want to post an image as well.

Here is what I have tried:

 byte[] data = null;
 Bitmap bi = BitmapFactory.decodeFile("R.drawable.plate1");
 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
 data = baos.toByteArray();
 parameters.putByteArray("picture", data);

 int plate = getResources().getIdentifier("com.b2creativedesigns.eyetest:drawable/plate1", null, null);
 parameters.putString("picture", String.valueOf(plate)); 

Neither of them works. When I try to post, nothing happens. Nothing is posted. With the code below, it works.

Posting the image from a website is easy, but it will not work, when the website gets shutdown or the links modified.

  parameters.putString("picture", "https://lh3.ggpht.com/f79UCpnLisZxO2P2C43f55YLvFpNco_cTcC-t9Ck-Qmqe5jwKbfnUvCh5N6-Te-mOw=w124");

3rd example:

  byte[] data = null;
  Bitmap bi = BitmapFactory.decodeFile("R.drawable.plate1");
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
  data = baos.toByteArray();
  parameters.putString("method", "photos.upload");
  parameters.putByteArray("picture", data);

解决方案

EDIT: Sorry, I shouldn't have gave advice on how to use the REST API since it's deprecated. This is how you upload a photo to your own wall using the Graph API.

Bundle params = new Bundle();
params.putByteArray("photo", data);
params.putString("caption", "Test photo upload");
    mAsyncRunner.request("me/photos", params, "POST",
    new PhotoUploadListener(), null);

Please try this and see if it works. This was taken straight out of our HackBook example in our documentation. For the compression of the image, you can use our Utility.scaleImage method inside our SDK which will do all the compression and scaling to match Facebook's standards.

==================================================================================

ORIGINAL MESSAGE:

photos.upload is using the REST API and is deprecated so I would recommend using the Graph API to upload photos but here's the quick and dirty solution using the REST API.

Once you have the byte array in a variable like data, do the following:

Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
mFacebook.request(params);

Let me know if that helps.