gpt4 book ai didi

Android Facebook SDK 3.0 session 状态 "Opening"

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:10:44 26 4
gpt4 key购买 nike

我正在使用他们的文档集成 Facebook 的登录。我遇到了一个问题,当我单击 Facebook 登录小部件时, session 更改为“正在打开”并且应用程序崩溃

我的 Facebook 按钮布局

 <com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
/>

fragment 是

public class FacebookFragment extends Fragment {
private static final String TAG = "FacebookFragment";
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(final Session session, final SessionState state, final Exception exception) {
onSessionStateChange(session, state, exception);
}
};

@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_likes", "user_status"));
return view;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(getActivity(), callback);
uiHelper.onCreate(savedInstanceState);
}

@Override
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null &&
(session.isOpened() || session.isClosed()) ) {
onSessionStateChange(session, session.getState(), null);
}

uiHelper.onResume();
}

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

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

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

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

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
else
Log.i(TAG, session.toString());
}

并且在 Activity 中我已经实现了所需的 onActivityResult 并检索了 fragment

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState == null) {
// Add the fragment on initial activity setup
mainFragment = new FacebookFragment();
getSupportFragmentManager()
.beginTransaction()
.add(android.R.id.content, mainFragment)
.commit();
} else {
// Or set the fragment from restored state info
mainFragment = (FacebookFragment) getSupportFragmentManager()
.findFragmentById(android.R.id.content);
}
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

我认为问题可能出在 key 哈希上,但我完全遵循了此问题上发布的答案中的说明 Key hash for Android-Facebook app

任何有关如何使状态变为“已打开”的线索都将不胜感激

最佳答案

问题在于在进行 facebook 登录的 Activity 中设置了 android:clearTaskOnLaunch="true"。无法调用 OnActivityResult。当我在 Debug模式下运行应用程序时,我能够得到一个异常。

关于Android Facebook SDK 3.0 session 状态 "Opening",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16420988/

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