Android将图片发布到Facebook公共页面墙
我目前可以通过以下方式发布到公共页面:Android将图片发布到Facebook公共页面墙,android,facebook,image-uploading,facebook-comments,facebook-android-sdk,Android,Facebook,Image Uploading,Facebook Comments,Facebook Android Sdk,我目前可以通过以下方式发布到公共页面: JSONObject json = new JSONObject(); json.put("message", "I'm on your wall"); Request req = Request.newPostRequest(getSession(), "PowerCardSoftware/feed", GraphObject.Factory.create(json), new Callback() { @Override
JSONObject json = new JSONObject();
json.put("message", "I'm on your wall");
Request req = Request.newPostRequest(getSession(), "PowerCardSoftware/feed", GraphObject.Factory.create(json), new Callback() {
@Override
public void onCompleted(Response response) {
if(response.getError() != null)
Log.e("FRAGACTIVITY", response.getError().toString());
Toast.makeText(getBaseContext(), "I hacked your facebook!", Toast.LENGTH_SHORT).show();
}
});
Request.executeBatchAsync(req);
我想把用户拍的照片也贴在公共墙上。我尝试过使用Bundle而不是JSONObject,并使用以下每一行:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
postPhoto.compress(CompressFormat.JPEG, 100, baos);
params.putByteArray("picture", baos.toByteArray());
params.putByteArray("source", baos.toByteArray());
他们都给了我这样一个错误-errorMessage:(#100)图片URL的格式不正确
有人知道如何在不使用facebook sdk中不推荐的功能/对象的情况下将照片发布到其他人的facebook墙上吗?这是我上传手机本地存储的照片的代码:
Request request6 = Request.newUploadPhotoRequest(
session,
((BitmapDrawable) getResources().getDrawable(
R.drawable.picture)).getBitmap(), callback6);
RequestAsyncTask task6 = new RequestAsyncTask(request6);
task6.execute();
这是上传到你自己的墙上。之所以没有选择另一个收件人的选项,是因为2月份发生了重大变化,将禁止在他人的墙上张贴
编辑:
上传照片的最佳方式是什么,照片和信息会出现在一个地方的墙上
你能试试看这个吗
Bundle parameters = new Bundle();
parameters.putParcelable("picture", YOUR_BITMAP_HERE);
parameters.putString("message", "my message for the page");
return new Request(session, "PowerCardSoftware/feed", parameters, HttpMethod.POST, callback);
我可以使用newUploadPhotoRequest()添加消息吗
不,要在照片中添加消息,您将不会使用
newUploadPhotoRequest
。如果深入研究源代码,它只是一个请求
的包装器,因此执行与方法相同的操作,但添加一个附加参数message
,并使用所需的消息执行它。我还没有亲自验证过,但应该能用。如果没有,请告诉我。这是我上传手机本地存储照片的代码:
Request request6 = Request.newUploadPhotoRequest(
session,
((BitmapDrawable) getResources().getDrawable(
R.drawable.picture)).getBitmap(), callback6);
RequestAsyncTask task6 = new RequestAsyncTask(request6);
task6.execute();
这是上传到你自己的墙上。之所以没有选择另一个收件人的选项,是因为2月份发生了重大变化,将禁止在他人的墙上张贴
编辑:
上传照片的最佳方式是什么,照片和信息会出现在一个地方的墙上
你能试试看这个吗
Bundle parameters = new Bundle();
parameters.putParcelable("picture", YOUR_BITMAP_HERE);
parameters.putString("message", "my message for the page");
return new Request(session, "PowerCardSoftware/feed", parameters, HttpMethod.POST, callback);
我可以使用newUploadPhotoRequest()添加消息吗
不,要在照片中添加消息,您将不会使用newUploadPhotoRequest
。如果深入研究源代码,它只是一个请求
的包装器,因此执行与方法相同的操作,但添加一个附加参数message
,并使用所需的消息执行它。我还没有亲自验证过,但应该能用。如果没有,请告诉我。这是我的解决方案。
我引用了他的答案并做了一些修改
Bitmap image = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "demo.jpg");
Bundle parameters = new Bundle();
parameters.putParcelable("source", image);
parameters.putString("message", "my message for the page");
Request request = new Request(Session.getActiveSession(), "me/photos", parameters, HttpMethod.POST, new Request.Callback() {
@Override
public void onCompleted(Response response) {
showPublishResult(mainActivity.getString(R.string.photo_post), response.getGraphObject(), response.getError());
}
});
request.executeAsync();
这是我的解决方案。
我引用了他的答案并做了一些修改
Bitmap image = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "demo.jpg");
Bundle parameters = new Bundle();
parameters.putParcelable("source", image);
parameters.putString("message", "my message for the page");
Request request = new Request(Session.getActiveSession(), "me/photos", parameters, HttpMethod.POST, new Request.Callback() {
@Override
public void onCompleted(Response response) {
showPublishResult(mainActivity.getString(R.string.photo_post), response.getGraphObject(), response.getError());
}
});
request.executeAsync();
您可以查看facebookSDK项目/测试文件夹和搜索关键字newPostRequest。 示例代码如下所示
GraphObject statusUpdate = GraphObject.Factory.create();
String message = "message";
statusUpdate.setProperty("message", message);
statusUpdate.setProperty("link", "http://stackoverflow.com/questions/14129546/android-post-picture-to-facebook-public-page-wall#");
Request request = Request.newPostRequest(Session.getActiveSession(), "me/feed", statusUpdate, new Callback() {
@Override
public void onCompleted(Response response) {
}
});
request.executeAsync();
您可以查看facebookSDK项目/测试文件夹和搜索关键字newPostRequest。 示例代码如下所示
GraphObject statusUpdate = GraphObject.Factory.create();
String message = "message";
statusUpdate.setProperty("message", message);
statusUpdate.setProperty("link", "http://stackoverflow.com/questions/14129546/android-post-picture-to-facebook-public-page-wall#");
Request request = Request.newPostRequest(Session.getActiveSession(), "me/feed", statusUpdate, new Callback() {
@Override
public void onCompleted(Response response) {
}
});
request.executeAsync();
什么是
数据
?您是否尝试过为图片
参数提供URL?现在应该更清楚了。如果我使用URL,我想它会起作用。但是我需要使用手机上本地存储的图像(后期照片)。什么是数据
?您是否尝试过为图片
参数提供URL?现在应该更清楚了。如果我使用URL,我想它会起作用。但是我需要使用手机上本地存储的图像(postPhoto)。如果没有方便的方法将照片从手机上的本地存储上传到某个地方的墙上,那么上传照片的最佳方式是什么,照片和信息会显示在某个地方的墙上?我可以使用newUploadPhotoRequest()添加消息吗?如果没有方便的方法将照片从手机上的本地存储发布到某个地方的墙上,那么上传照片的最佳方法是什么?照片和消息将显示在某个地方的墙上?我可以使用newUploadPhotoRequest()添加消息吗?