借助Android 2.1,如何将图像上传到Facebook墙?图像存储在SDCard中.
解决方法:
您应该使用Facebook API http://developers.facebook.com/docs/guides/mobile/#android.
然后使用以下代码:
byte[] data = null;
try {
FileInputStream fis = new FileInputStream(PATH_TO_FILE);
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
} catch (FileNotFoundException e) {
e.printstacktrace();
Log.d("onCreate", "debug error e = " + e.toString());
}
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
Facebook facebook = new Facebook(FACEBOOK_APP_ID);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new RequestListener() {
public void onMalformedURLException(MalformedURLException e, Object state) {
Log.d("request RequestListener", "debug onMalformedURLException");
}
public void onIOException(IOException e, Object state) {
Log.d("request RequestListener", "debug onIOException");
}
public void onFileNotFoundException(FileNotFoundException e, Object state) {
Log.d("request RequestListener", "debug onFileNotFoundException");
}
public void onFacebookError(FacebookError e, Object state) {
Log.d("request RequestListener", "debug onFacebookError");
}
public void onComplete(String response, Object state) {
Log.d("request RequestListener", "debug onComplete");
}
}, null);
确保您的应用程序有权访问互联网和sdcard
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。