某些设备上的Facebook登录失败

时间:2013-06-24 14:53:03

标签: android facebook facebook-login

我已经实现了Facebook登录,并且在某些设备/ AVD上工作正常。我的开发设备是姜饼手机,但是用4.1.1设备测试它,它根本就没有登录。按下facebook按钮后,它显示一个空白屏幕(试图连接Facebook),1-2秒后它回到主屏幕。此外,Logcat中没有任何错误被烘烤或显示。哦,Facebook应用程序安装在设备中......有什么想法吗?

更新

我按照Mark Venzke建议并使用this程序启用了日志记录,每次登录尝试都会收到此警告(两次)(注意:使用HTC One S手机进行测试):

07-05 20:14:50.582: W/PackageManager(605): Unable to load service info ResolveInfo{4171dbf0 com.htc.socialnetwork.facebook.remote.FacebookSyncService p=0 o=0 m=0x108000}

请注意com.htc.socialnetwork.facebook.remote.FacebookSyncService行,那么HTC设备是否需要额外的步骤?

另外,我正在附加执行登录的代码:

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (isResumed) {
        FragmentManager manager = getSupportFragmentManager();
        int backStackSize = manager.getBackStackEntryCount();
        for (int i = 0; i < backStackSize; i++) {
            manager.popBackStack();
        }
        com.facebook.Settings.addLoggingBehavior(LoggingBehavior.REQUESTS);
        if (state.isOpened()) {

            Bundle params = new Bundle();
            params.putString("fields", "id");
            params.putString("limit", "1");             
            Request request = new Request(Session.getActiveSession(), "me", params, HttpMethod.GET, new Callback()
            {

                @Override
                public void onCompleted(Response response)
                {
                    if (response != null)
                    {
                        Log.d("AuthGraphResponse", response.toString());
                        long id;
                        try {
                            id = response.getGraphObject().getInnerJSONObject().getLong("id");
                            app.setFacebookId(id);
                            Log.d("UserID", Long.valueOf(id).toString());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();

            showFragment(AUTH, false);
        } else if (state.isClosed()) {
            showFragment(UNAUTH, false);
        }
    }
}

更新2:

HTC是否有可能将所有设备(或其中一些设备中的默认Facebook应用程序的包名称)重命名为com.htc.socialnetwork.facebook(而不是com.facebook.katana),并导致这场冲突?我真的不认为卸载默认应用程序并从Google Play安装Facebook是一种可接受的解决方案(另外,我认为默认应用程序无法卸载)。

更新3:

尚未解决。 19小时奖励100个声望赏金!

更新4:

LogCat另一个有趣的路线:

07-15 10:55:51.718: E/chromium(30475): external/chromium/net/disk_cache/stat_hub.cc:216: [0715/105551:ERROR:stat_hub.cc(216)] StatHub::Init - App com.facebook.katana isn't supported.

10 个答案:

答案 0 :(得分:6)

您的股票应用与SDK之间肯定存在冲突。因此,如果您不想安装HTC应用程序并且仍然使用SDK 3.0,我认为您最好的选择是在不修改sdk的源代码的情况下禁用SSO并仅通过webview登录。

每次尝试打开新会话时,都可以通过添加SessionLoginBehavior.SUPRESS_SSO轻松完成。以下是我从Facebook SDK中更改SessionLoginSample(LoginUsingActivityActivity)的示例,以向您展示如何操作:

@Override
public void onCreate(Bundle savedInstanceState) {
    ...
    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
            session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
        }
        if (session == null) {
            session = new Session(this);
        }
        Session.setActiveSession(session);

        //add the check, for if session is opened
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED) || !session.getState().isOpened()) {
            //Add the suppress SSO behavior to force webview auth dialog to popup
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback).setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO));
        }
    }
  ...
}
//then put your code in the statusCallback method or keep it in the session state change listener

否则如果你不介意更改facebook sdk代码,你应该检查this

答案 1 :(得分:4)

Shirley Facebook登录并未在所有4.1.1设备上破解,因此它与您的实施有关。

您确定Key Hash在该设备上与您在developer.facebook.com上配置的相同吗?如果您使用了不同的开发密钥,或者它是由第三方商店安装的,则密钥哈希值可能不匹配。

打开Facebook SDK源代码中的调试日志记录并重建它。出于安全原因,它通常默认关闭。根据您的SDK版本,它可能位于Util.java或其他位置,可能是名为“ENABLE_LOG”的变量。

答案 2 :(得分:2)

我认为facebook登录错误大多发生,所以为了解决这个问题,你一步一步地耐心地跟着教程。

其他方面很难解决你的问题。所以你可以参考这个链接。

http://developers.facebook.com/android/

我希望你能成功。

答案 3 :(得分:1)

您的问题中没有足够的信息。所以,我在这里做了一些猜测。

1)首先看看Mike Venzke的答案。

2)如果这不起作用,那么试试这个: 您需要使用SSO(单点登录)登录您的设备。以下是您可以采取的步骤。

删除构建。重新安装它。当您被要求获取设备的权限时,请允许它们。

如果您没有收回应用程序,则需要将这些内容添加到清单文件中:

<activity
        android:name="com.facebook.LoginActivity"
        android:label="@string/app_name" >
    </activity>
<meta-data android:value="@string/app_id" android:name="com.facebook.sdk.ApplicationId"/>

其中app_name和app_id是您的Facebook应用页面上各自的应用ID和应用名称。

你添加了这些顺便说一句吗?

您还需要这些权限

<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

如果您发布更多信息,我可能会猜到这个问题。

答案 4 :(得分:1)

我认为您的Facebook Android应用在设备中的问题。所以首先从设备上卸载facebook android app并检查facebook登录是否正常工作。

答案 5 :(得分:1)

由于Honeycomb您无法在主线程上进行互联网调用,请尝试使用Android AsyncTask或自行创建新线程。

http://developer.android.com/reference/android/os/AsyncTask.html

答案 6 :(得分:0)

使用旧版facebook的设备时出现此错误。完全删除Facebook,或更新Facebook应用程序修复它。

我很确定会发生这种情况,因为Facebook for Android曾经只是一个包装好的移动网站WebView。

另请注意,如果您尝试删除某些设备(我的Incredible 4G LTE)将重新安装旧的(webview)版本的facebook。

答案 7 :(得分:0)

将设备连接到eclipse以查看logcat。如果log cat未在Windows中运行打开cmd提示符并运行adb restart,(首先设置adb路径)。然后你可以看到logcat正在运行。现在打开您的应用程序并单击Facebook登录按钮。你可以在log cat中获得黄色的正确哈希键。将该密钥放在Facebook上,现在facebook登录将在每台设备上运行。感谢。

答案 8 :(得分:0)

List<String> permissions = new ArrayList<String>();
permissions.add("email");



//start Facebook session
openActiveSession(this, true, new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        if (session.isOpened()) {
            //make request to the /me API

            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                @Override
                public void onCompleted(GraphUser user, Response response) {
                    if (user != null) {
                        String firstName = user.getFirstName();
                        String lastName = user.getLastName();
                        String id = user.getId();
                        String email=null;
                        try {
                            email = user.getProperty("email").toString();
                        } catch (Exception e) {
                            // TODO: handle exception
                        }

                        String gender = (String) user.getProperty("gender");
                        String birthday = user.getBirthday();



                    //welcome.setText("Hello \n" + firstName+"\n"+lastName+"\n"+email+"\n"+gender+"\n"+birthday+"!");




                    if(firstName!=null)
                    {


                          SharedPreferences.Editor editor = settings.edit();

                            editor.putString("fligin", "1");
                            editor.putString("firstName", firstName);
                            editor.putString("lastName", lastName);
                            editor.putString("email", email);
                            editor.putString("gender", gender);
                            editor.putString("birthday", birthday);
                            editor.commit();

                        Intent intent=new Intent(getApplicationContext(), RegistrationOneActivity.class);
                        startActivity(intent);
                        //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );

                        finish();
                    }
                    else {

                        Toast.makeText(getApplicationContext(),"Person information is null", Toast.LENGTH_SHORT).show();

                    finish();
                        }



                    }
                }
            });
         }
     }
 }, permissions);

答案 9 :(得分:0)

尝试在java源代码中定义登录按钮的位置插入此行

LoginButton fb_button = (LoginButton)findViewById(//your resource id);
fb_button.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);