参考此answer,我曾尝试使用Facbook SDK上传图像,但是根据Facebook SDK文档,它已经提到“该类在最新版本的SDK中不再可用”请求类。但是我想上传相册图像以及我分享的帖子。那么,当前SDK版本的photos.upload替代品是什么?请告知,代码示例将非常有用,谢谢。.
上述问题的代码段,我在我的代码中尝试过该代码段,该代码段已不再可用:
String status =
"#Beats #" + (PlayerService.getCurrentTrack().getAlbum()).replace(" ", "") + " #"
+ (PlayerService.getCurrentTrack().getArtist()).replace(" ", "");
InputStream imageStream =
getContentResolver().openInputStream(Uri.parse(PlayerService.getCurrentTrack().getAlbumArtUri()));
Bitmap mShareBitmap = BitmapFactory.decodeStream(imageStream);
String fbPhotoAddress = null;
Request.Callback uploadPhotoRequestCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
if (isFinishing()) {
return;
}
if (response.getError() != null) { // [IF Failed Posting]
Log.d(logtag, "photo upload problem. Error="+response.getError() );
} // [ENDIF Failed Posting]
Object graphResponse = response.getGraphObject().getProperty("id");
if (graphResponse == null || !(graphResponse instanceof String) ||
TextUtils.isEmpty((String) graphResponse)) { // [IF Failed upload/no results]
Log.d(logtag, "failed photo upload/no response");
} else { // [ELSEIF successful upload]
fbPhotoAddress = "https://www.facebook.com/photo.php?fbid=" +graphResponse;
} // [ENDIF successful posting or not]
} // [END onCompleted]
};
//Part 2: upload the photo
Request request = Request.newUploadPhotoRequest(session, imageSelected, uploadPhotoRequestCallback);
request.executeAsync();