gpt4 book ai didi

android - Facebook 共享对话框 PostId 为空

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

我正在通过 Android 中的共享对话框在 FB 上共享视频。共享工作得很好。但是,FB post id 返回 null。回调甚至在视频上传之前就返回了。如果我遗漏了什么,请告诉我。下面是我的代码。

public class TestFragment extends Fragment {

private CallbackManager callbackManager;
private ShareDialog shareDialog;

public TestFragment() {
// Required empty public constructor
}

public static TestFragment newInstance(String path, String json) {
TestFragment fragment = new TestFragment();
return fragment;
}

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

FacebookSdk.sdkInitialize(getActivity());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
// this part is optional
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
Timber.d("result.getPostId() :: " + result.getPostId());
}

@Override
public void onCancel() {
Timber.d("Facebook : Cancelled");
}

@Override
public void onError(FacebookException e) {
Timber.d(e.getMessage());
}
});
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_test, container, false);
ButterKnife.inject(this, view);
return view;
}

@OnClick(R.id.facebookShare)
public void share() {
Timber.d("share button pressed");
if (ShareDialog.canShow(ShareVideoContent.class)) {
Timber.d("showing share dialog");
shareDialog.show(getVideoContent());
} else {
Timber.d("unable to show the share dialog");
}
}

private ShareVideoContent getVideoContent() {
Timber.d(mVideoMetadata.getVideoId());

ShareVideo shareVideo = new ShareVideo.Builder()
.setLocalUrl(Uri.parse("... file ..."))
.build();
ShareVideoContent content = new ShareVideoContent.Builder()
.setVideo(shareVideo)
.build();

return content;
}

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}

最佳答案

shareDialog.show(shareContent, ShareDialog.Mode.FEED);

将模式设置为 ShareDialog.Mode.FEED。
它对我有用。

Here's example

关于android - Facebook 共享对话框 PostId 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881861/

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