gpt4 book ai didi

Android-Facebook SDK : Unable to share photo, 对话框未显示

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:59 26 4
gpt4 key购买 nike

这是我第一次使用 Android-Facebook SDK。我正在尝试发布位图,但我一直收到此消息:

Warning: Error: com.facebook.FacebookException: Failed to copy image.

我可以发布简单的链接,但不能发布带有照片的链接。

我应该如何解决这个问题?另外,我注意到的一件事是没有调用 StatusCallback.call()。

public abstract class FacebookReadyBaseActivity extends Activity {
private static final String TAG = "FacebookReadyBaseActivity";

private UiLifecycleHelper uiHelper;

protected PendingAction pendingAction = PendingAction.NONE;
private static final String PERMISSION = "publish_actions";
protected boolean canPresentShareDialogWithPhotos;
private boolean canPresentShareDialog;
private GraphUser user;
private GraphPlace place;
private List<GraphUser> tags;
protected Bitmap pendingBitmap;

protected enum PendingAction {
NONE, POST_PHOTO, POST_STATUS_UPDATE
}

private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChange(session, state, exception);
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);

canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,
FacebookDialog.ShareDialogFeature.SHARE_DIALOG);
canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(
this, FacebookDialog.ShareDialogFeature.PHOTOS);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

uiHelper.onActivityResult(requestCode, resultCode, data,
new FacebookDialog.Callback() {
@Override
public void onError(FacebookDialog.PendingCall pendingCall,
Exception error, Bundle data) {
Log.e(TAG, String.format("Error: %s", error.toString()));
}

@Override
public void onComplete(
FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i(TAG, "Success!");
}
});
}

@Override
protected void onResume() {
super.onResume();
uiHelper.onResume();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}

@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
}

@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}

protected UiLifecycleHelper getFacebookUiHelper() {
return uiHelper;
}

protected void performPublish(PendingAction action, boolean allowNoSession) {
Session session = Session.getActiveSession();
if (session != null) {
pendingAction = action;
if (hasPublishPermission()) {
// We can do the action right away.
handlePendingAction();
return;
} else if (session.isOpened()) {
// We need to get new permissions, then complete the action when
// we get called back.
session.requestNewPublishPermissions(new Session.NewPermissionsRequest(
this, PERMISSION));
return;
}
}

if (allowNoSession) {
pendingAction = action;
handlePendingAction();
}
}

private boolean hasPublishPermission() {
Session session = Session.getActiveSession();
return session != null
&& session.getPermissions().contains("publish_actions");
}

@SuppressWarnings("incomplete-switch")
private void handlePendingAction() {
PendingAction previouslyPendingAction = pendingAction;
// These actions may re-set pendingAction if they are still pending, but
// we assume they
// will succeed.
pendingAction = PendingAction.NONE;

switch (previouslyPendingAction) {
case POST_PHOTO:
postPhoto();
break;
case POST_STATUS_UPDATE:
postStatusUpdate();
break;
}
}

private void postPhoto() {

if (canPresentShareDialogWithPhotos) {
FacebookDialog shareDialog = createShareDialogBuilderForPhoto(
pendingBitmap).build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else if (hasPublishPermission()) {
Request request = Request.newUploadPhotoRequest(
Session.getActiveSession(), pendingBitmap,
new Request.Callback() {
@Override
public void onCompleted(Response response) {
InfoDialog.newInstance(
FacebookReadyBaseActivity.this, "Done",
"Photo share finished.", null).show();
}
});
request.executeAsync();
} else {
pendingAction = PendingAction.POST_PHOTO;
}
}

private void postStatusUpdate() {
if (canPresentShareDialog) {
FacebookDialog shareDialog = createShareDialogBuilderForLink()
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
} else if (user != null && hasPublishPermission()) {
// TODO fixme
final String message = "Status update finished.";
Request request = Request.newStatusUpdateRequest(
Session.getActiveSession(), message, place, tags,
new Request.Callback() {
@Override
public void onCompleted(Response response) {

InfoDialog.newInstance(
FacebookReadyBaseActivity.this, "Done",
message, null).show();
}
});
request.executeAsync();

} else {
pendingAction = PendingAction.POST_STATUS_UPDATE;
}
}

private FacebookDialog.PhotoShareDialogBuilder createShareDialogBuilderForPhoto(
Bitmap... photos) {
return new FacebookDialog.PhotoShareDialogBuilder(this)
.addPhotos(Arrays.asList(photos));
}

private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForLink() {
return new FacebookDialog.ShareDialogBuilder(this)
.setName("Hello Facebook")
.setDescription(
"The 'Hello Facebook' sample application showcases simple Facebook integration")
.setLink("http://developers.facebook.com/android");
}


private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (pendingAction != PendingAction.NONE
&& (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) {
InfoDialog.newInstance(FacebookReadyBaseActivity.this, "Failed",
"Not granted.", null).show();
pendingAction = PendingAction.NONE;
} else if (state == SessionState.OPENED_TOKEN_UPDATED) {
handlePendingAction();
}

}

}

最佳答案

终于成功了!

在提供的 HelloFacebookSample 项目中,我在 list 中看到了这一点:

 <provider android:authorities="com.facebook.app.NativeAppCallContentProvider355198514515820"
android:name="com.facebook.NativeAppCallContentProvider"
android:exported="true"/>

我只是使用自己的 Facebook 应用程序 ID 更改了数字部分。不知道为什么我没有在文档中看到这一点。

编辑后来发现:https://developers.facebook.com/docs/reference/android/current/class/NativeAppCallContentProvider/

关于Android-Facebook SDK : Unable to share photo, 对话框未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23532675/

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