gpt4 book ai didi

android - Facebook 连接 3.5 session : an attempt was made to open an already opened session

转载 作者:行者123 更新时间:2023-11-30 02:58:59 27 4
gpt4 key购买 nike

当我点击下面的 fbconnect 时:

fbconnect.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// Check for an open session

/*Session session = Session.getActiveSession();

if (!session.isOpened() && !session.isClosed()) {
System.out.println("hereinfb");
session.openForRead(new Session.OpenRequest(getActivity())
.setCallback(callback).setPermissions(
Arrays.asList("basic_info", "email",
"user_photos")));
;

fbconnect(session);

} else {
System.out.println("hereinfb1");
Session.openActiveSession(getActivity(), true, callback);

fbconnect(session);

}*/


session = Session.getActiveSession();

session.openForRead(new Session.OpenRequest(m).setCallback(
callback).setPermissions(
Arrays.asList("basic_info", "email", "user_photos")));

Session.openActiveSession(getActivity(), true, callback);

System.out.println("fbsession" + session);

if (session != null) {
// Get the user's data

fbconnect(session);

}

/*
*
* Session session = Session.getActiveSession();
* System.out.println("fbsession" + session); if (session !=
* null) { // Get the user's data fbconnect(session); }else {
*
* fbconnect(session);
*
* }
*/

}
});

应用程序强制关闭和错误日志显示:

04-03 14:14:14.164: E/AndroidRuntime(29386): FATAL EXCEPTION: main
04-03 14:14:14.164: E/AndroidRuntime(29386): java.lang.UnsupportedOperationException: Session: an attempt was made to open an already opened session.
04-03 14:14:14.164: E/AndroidRuntime(29386): at com.facebook.Session.open(Session.java:985)
04-03 14:14:14.164: E/AndroidRuntime(29386): at com.facebook.Session.openForRead(Session.java:388)
04-03 14:14:14.164: E/AndroidRuntime(29386): at com.orange.re.SlidingMenuFragment$3.onClick(SlidingMenuFragment.java:123)
04-03 14:14:14.164: E/AndroidRuntime(29386): at android.view.View.performClick(View.java:4475)
04-03 14:14:14.164: E/AndroidRuntime(29386): at android.view.View$PerformClick.run(View.java:18786)
04-03 14:14:14.164: E/AndroidRuntime(29386): at android.os.Handler.handleCallback(Handler.java:730)
04-03 14:14:14.164: E/AndroidRuntime(29386): at android.os.Handler.dispatchMessage(Handler.java:92)
04-03 14:14:14.164: E/AndroidRuntime(29386): at android.os.Looper.loop(Looper.java:137)
04-03 14:14:14.164: E/AndroidRuntime(29386): at android.app.ActivityThread.main(ActivityThread.java:5419)
04-03 14:14:14.164: E/AndroidRuntime(29386): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 14:14:14.164: E/AndroidRuntime(29386): at java.lang.reflect.Method.invoke(Method.java:525)
04-03 14:14:14.164: E/AndroidRuntime(29386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-03 14:14:14.164: E/AndroidRuntime(29386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-03 14:14:14.164: E/AndroidRuntime(29386): at dalvik.system.NativeStart.main(Native Method)

这一行使应用程序崩溃。

session.openForRead(new Session.OpenRequest(m).setCallback(
callback).setPermissions(
Arrays.asList("basic_info", "email", "user_photos")));

最佳答案

session = Session.getActiveSession();

Activity session 已经打开。你不需要打开它。我是这样做的:

Session session = Session.getActiveSession();
if (session != null && session.isOpened())
{

List<String> permissions = session.getPermissions();

if (!permissions.contains("publish_actions"))
{
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(FBLogin.this, Arrays.asList("publish_actions"));

session.requestNewPublishPermissions(newPermissionsRequest);
}
}

https://github.com/madhur/MapMyLocation/blob/develop/src/in/co/madhur/mapmylocation/activity/FBLogin.java

关于android - Facebook 连接 3.5 session : an attempt was made to open an already opened session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22835332/

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