如何发布SD卡的图像到Facebook的墙壁使用图形API墙壁、图形、图像、SD

2023-09-12 08:21:29 作者:無你不成家

可能重复:   How使用图形API 张贴图片的Facebook墙上

Possible Duplicate: How to post image to facebook wall using graph api

我使用的图形API张贴在Facebook墙上。

I am using Graph API to post on Facebook wall.

strpostimageurl=/mnt/sdcard/DCIM/mnt/sdcard/DCIM/Camera1354795516555.jpg

String res = UrltoValue.getValuefromUrl("https://graph.facebook.com/"+Login.facebookid+"/feed?access_token="+accesstoken+"&method="+"post"+"&message="+"hi"+"&link="+strpostimageurl);

我收到错误的请求作为响应。

I am getting Bad Request as a response.

是否有可能给Micro-SD卡路径张贴图片?我有只位图对象,所以我创建的文件与位图和我使用的。

Is it possible to give SD-Card path for Posting images? I am having only Bitmap of the object, so I created file with that Bitmap and I am using that.

和我需要张贴在多个好友留言,让我preferring使用图形API。

And I need to post on multiple friends wall,so I am preferring to use Graph API.

推荐答案

您所得到的的错误的请求的错误,因为您传递了错误的值到Facebook的API。

You are getting the Bad Request error because you are passing the wrong values to the Facebook API.

首先,如果您上传的图片/照片通过链接或URL,那么你必须使用的源的标记和不可以的 链接的标签,你在你的code。

First, if you are uploading an Image / Photo via a link or an URL, then you have to use the "source" tag and not the "link" tag as you have in your code.

第二,如果你是修复以上,我怀疑code将工作看,你的 strpostimageurl 实际上并没有一个有效的URL。

Second, if you were to fix the above, I doubt the code would work seeing that your strpostimageurl does not actually have a valid URL.

第三,因为它不是一个有效的URL,使用标签将不会是一种选择。您将需要使用这样的:

Third, since it is not a valid URL, using the "source" tag would not be an option. You will need to use something like this:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmpImageGallery.compress(CompressFormat.JPEG, 100, baos);

Bundle postImgGallery = new Bundle();

// ADD THE PHOTO DATA TO THE BUNDLE
postImgGallery.putByteArray("photo", baos.toByteArray());

// ADD THE CAPTION FROM THE STRING finalStatusMessage TO THE BUNDLE
if (finalStatusMessage.equals(""))  {
    /*****  DO NOTHING HERE     *****/
} else {
    postImgGallery.putString("caption", finalStatusMessage);
}

mAsyncRunner.request("me/photos", postImgGallery, "POST", new PhotoUploadListener(), null);

下面,

mAsyncRunner AsyncFacebookRunner类这是Facebook的SDK的一部分的一个实例。 bmpImageGallery 位图,其中,由用户选择的图像存储的实例。它得到利用从图库中的用户选择的图像: mAsyncRunner is an instance of the AsyncFacebookRunner Class that is part of the Facebook SDK. bmpImageGallery is an instance of a Bitmap in which the Image selected by the user is stored. It gets the Image selected by the User from the gallery using:

这是code在按钮的的OnClick 赛事运行打开的画廊和让用户从中选择一个照片/图片:

This is code runs on the OnClick event of a Button that opens the Gallery and lets the User select a Photo / Image from it:

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, reqcdGalleryImage);

然后,使用 onActivityResult()的方法,所选择的图像传递给位图例如 bmpImageGallery 在code早期使用的:

Then, using the onActivityResult() method, the selected image is passed to the Bitmap instance bmpImageGallery used in the code earlier:

bmpImageGallery = MediaStore.Images.Media.getBitmap(this.getContentResolver(), targetURI);

编辑:

那就试试这个(的OnClick):

Then try this (OnClick) :

Intent getCameraImage = new Intent("android.media.action.IMAGE_CAPTURE");

File cameraFolder;

if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
    cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"give_a_folder_name/camera");
else
    cameraFolder= StatusUpdate.this.getCacheDir();
if(!cameraFolder.exists())
    cameraFolder.mkdirs();

File photo = new File(Environment.getExternalStorageDirectory(), "give_a_folder_name/camera/camera_snap.jpg");
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
initialURI = Uri.fromFile(photo);

startActivityForResult(getCameraImage, 2);

在此 onActivityResult()

targetURI = initialURI;
getContentResolver().notifyChange(targetURI, null);

ContentResolver cr = getContentResolver();

try {

    // SET THE IMAGE FROM THE CAMERA TO THE IMAGEVIEW
    bmpImageCamera = android.provider.MediaStore.Images.Media.getBitmap(cr, targetURI);

    // SET THE IMAGE FROM THE GALLERY TO THE IMAGEVIEW
    imgvwSelectedImage.setImageBitmap(bmpImageCamera);

} catch (Exception e) {
    e.printStackTrace();
}

在targetURI中和initialURI是全局声明开放的情况下,

The targetURI and initialURI are Uri instances declared globally