我正在尝试开发一个将图像上传到我的墙上的应用程序。我这样做了,但我无法添加捆绑包中的名称、标题等。因为 newUploadPhotoRequest() 方法只需要 3 个参数(sessoin、bitmap、callback)。请给我确切的完整代码。感谢你
我的代码如下:此方法用于发布图像:
公共无效图像加载(){
Session session = Session.getActiveSession();
if (session.isOpened())
{ Toast.makeText(MainActivity.this, "IN image load IF", Toast.LENGTH_SHORT).show();
Bundle postParams = new Bundle();
postParams.putString("name", "Name here.");
postParams.putString("caption", "Caption here.");
postParams.putString("description", "Description here.");
postParams.putString("link", "https://developers.facebook.com/android");
byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Bitmap bi = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
//Bitmap bi = BitmapFactory.decodeFile("/sdcard/viewitems.png");
bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
//postParams.putString("method", "photos.upload");
postParams.putByteArray("picture", data);
Request.Callback callback = new Request.Callback()
{
public void onCompleted(Response response)
{
FacebookRequestError error = response.getError();
if (error != null)
Toast.makeText(MainActivity.this , error.getErrorMessage(), Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "Posted successful on your wall", Toast.LENGTH_SHORT).show();
}
};
//Request request = new Request(session, "feed", postParams, HttpMethod.POST, callback);
//RequestAsyncTask task = new RequestAsyncTask(request);
//task.execute();
Request request = Request.newUploadPhotoRequest(session, bi, callback);
request.executeAsync();
}
else{
Toast.makeText(MainActivity.this, "login first", Toast.LENGTH_SHORT).show();
}