我正在使用SDK 3.6发布消息和照片。下面的代码给出了响应,如“Unsupported Methods,Photos.upload”
我参考了下面的Stackoverflow。
Android post picture to Facebook wall
有什么不对吗?如何上传图片(不是来自网址),并在Facebook上一起发送消息
private void postPhoto1()
{
if (hasPublishPermission()) {
Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
Session session = Session.getActiveSession();
Bundle postParams = new Bundle();
Byte[] data = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
postParams.putString("method", "photos.upload");
postParams.putByteArray("picture", data);
Request request = new Request(session, "me/photos", postParams, HttpMethod.POST, new Request.Callback() {
@Override
public void onCompleted(Response response) {
showPublishResult(getString(R.string.successfully_posted_post), response.getGraphObject(), response.getError());
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
} else {
pendingAction = PendingAction.POST_PHOTO;
}
}
答案 0 :(得分:0)
我删除了它并发布了它。
postParams.putString("method", "photos.upload");
并使用下面的行显示其成功发布的图片。
postParams.putByteArray("picture", data);
postParams.putString("message", messageval );
答案 1 :(得分:-1)
如果获得发布权限
,请尝试使用此代码public void postImage(){
byte[] data = null;
File imagefile = new File(Path);
FileInputStream fis = null;
try {
fis = new FileInputStream(imagefile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Bitmap bm = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG,100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
Toast.makeText(getApplicationContext(), "Image Posted on Facebook.", Toast.LENGTH_SHORT).show();
}