gpt4 book ai didi

android - 如何从 SD 卡上传图片到 Facebook?

转载 作者:行者123 更新时间:2023-11-29 00:05:13 25 4
gpt4 key购买 nike

我在这里放置了我的代码,谁能告诉我哪里出了问题?

代码

private void onFbLogin() {
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("user_friends"));
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
System.out.println("Success");
if (ShareDialog.canShow(ShareLinkContent.class)) {
File sdCard = Environment.getExternalStorageDirectory();
File file = new File(sdCard, "final_card.jpg");



ShareLinkContent content = new ShareLinkContent.Builder()//
.setContentUrl(Uri.parse("file:///sdcard/sharing_event.jpg"))
.setContentDescription("some desc")
.setContentTitle("Chennai")
.build();
shareDialog.show(content);
}
}

@Override
public void onCancel() {
showAlert();
}

@Override
public void onError(FacebookException error) {
showAlert();
}

private void showAlert() {
new AlertDialog.Builder(FinalCardView.this)
.setTitle(getString(R.string.cancelled))
.setMessage(getString(R.string.permission_not_granted))
.setPositiveButton(getString(R.string.ok), null)
.show();
}
});
}

最佳答案

是否要分享图片-需要使用SharePhoto photo

SharePhoto photo = new SharePhoto.Builder()
.setBitmap(bitmap)
.build();
SharePhotoContent content = new SharePhotoContent.Builder()
.addPhoto(photo)
.build();

这样就可以得到一个位图文件

Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()

关于android - 如何从 SD 卡上传图片到 Facebook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34332323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com