Android开发:在Facebook墙上张贴Screencap图像
我一直在到处寻找使用android和facebook sdk将图像+文本发布到facebook的正确方法。我可以让这段代码只发布一条消息,但当我尝试发布屏幕截图时,它最终会出现空指针异常。我尝试了许多其他线程的不同代码片段,但似乎没有一个适合我。我能做的最好的事情就是这个代码,它会在我的墙上发布一条消息,但不会在照片上。请告诉我我做错了什么。非常感谢Android开发:在Facebook墙上张贴Screencap图像,android,eclipse,facebook,photo,Android,Eclipse,Facebook,Photo,我一直在到处寻找使用android和facebook sdk将图像+文本发布到facebook的正确方法。我可以让这段代码只发布一条消息,但当我尝试发布屏幕截图时,它最终会出现空指针异常。我尝试了许多其他线程的不同代码片段,但似乎没有一个适合我。我能做的最好的事情就是这个代码,它会在我的墙上发布一条消息,但不会在照片上。请告诉我我做错了什么。非常感谢 View content = findViewById(R.id.row1); Log.d("captureScreen", co
View content = findViewById(R.id.row1);
Log.d("captureScreen", content.getId()+"");
byte[] byteArray=null;
Bitmap screenshot=null;
try {
if (content != null) {
int width = content.getWidth();
int height = content.getHeight();
screenshot = Bitmap.createBitmap(width, height,
Bitmap.Config.RGB_565);
content.draw(new Canvas(screenshot));
Log.d("captureScreen", "success");
}
} catch (Exception e) {
Log.d("captureScreen", "Failed");
}
try{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
screenshot.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
Log.d("byte array", "sucesss");
} catch(Exception e){
Log.d("byte array", "failed");
}
Request.Callback callback = new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response.getGraphObject()
.getInnerJSONObject();
Log.d("onCompleted", "2 sucess");
String postId = null;
try {
postId = graphResponse.getString("id");
Log.d("onCompleted", "3 sucess");
} catch (JSONException e) {
Log.d("json failed", "failed");
Log.i(TAG, "JSON error " + e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
} else {
CreateDialog("your post was a sucess", "posted");
}
}
};
Bundle params = new Bundle();
params.putString("message","tester");
//params.putString("method", "photos.upload");
//params.putByteArray("source", byteArray);
// params.putString("caption", "test Caption");
Request request = new Request(session, "me/photos", params,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
在我的应用程序中,我使用以下代码在Facebook上共享照片+文本
ByteArrayOutputStream baos = new ByteArrayOutputStream();
yourbitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
params.putString("caption",
"This is screen shot from MyApp. Visit my application blah blah blah");
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST",
new SampleUploadListener(), null);
您好,非常感谢您的回复,当我把这段代码放进去时,它说SampleUploadListener无法解析为一种类型,这是否意味着我把我的facebook类搞砸了?谢谢again@itburnz,你能告诉我你使用的FBAPI链接吗?SampleUploadListener只是有了这个实现“公共类SampleUploadListener扩展了BaseKeyListener实现了RequestListener”嗨,我从下载链接得到了sdk这里没有任何名为“BaseKeyListener”的类吗?和名为“RequestListener”的接口?您不需要通过实现这两个类来创建一个类,您就完成了。让我检查一下您的开发人员的链接。我使用了APIv2,您使用的是APIv3.nope没有称为basekeylistner或requestlistener的类,嗯,我应该降级到v2吗?我听说有一些不同,我看到人们使用我们不赞成的很多东西。