0

我正在开发一个应该与 Facebook 集成的 android 应用程序。我正在使用 Facebook 教程来了解如何做到这一点,但我已经连续几天收到这个错误了。我在我的 android 模拟器中安装了 Facebook 应用程序,并在 Facebook 中配置了我的密钥哈希。(我已经尝试过 cygwin 但它没有用,所以我在其他问题中阅读时分了 3 个不同的步骤)

我浏览了所有相关的问题,但我无法得到答案。我得到的只是错误,上面有一个带有“facebook”标志的空白页面。

编辑:现在我也收到一条消息:“MyApp 为 facebook 登录配置错误。按确定返回应用程序而不将其连接到 facebook。”

我的代码:

public class LoginActivity extends Activity {
    Facebook facebook;
    private SharedPreferences prefs;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        facebook = new Facebook(getString(R.string.facebookAppId));

        prefs = getPreferences(MODE_PRIVATE);
        String access_token = prefs.getString("access_token", null);
        long expires = prefs.getLong("access_expires", 0);
        if(access_token != null) {
            facebook.setAccessToken(access_token);
        }
        if(expires != 0) {
            facebook.setAccessExpires(expires);
        }
        if(!facebook.isSessionValid()) {

            facebook.authorize(this, new String[] {"email", "read_friendlists"}, new DialogListener() {
                public void onComplete(Bundle values) {
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putString("access_token", facebook.getAccessToken());
                    editor.putLong("access_expires", facebook.getAccessExpires());
                    editor.commit();
                }
                public void onFacebookError(FacebookError error) {
                    System.out.println("onFacebookError()");
                    error.printStackTrace();
                }
                public void onError(DialogError e) {}
                public void onCancel() {}
            });
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try{
            facebook.authorizeCallback(requestCode, resultCode, data);
        }finally{
            finish();
        }
    }

    @Override
    public void onResume() {    
        super.onResume();
        //extend facebook session
        facebook.extendAccessTokenIfNeeded(this, null);
    }
}
4

1 回答 1

0

I solved the problem. for people getting the same problem, so, i don't know why but if you make the login activity as main activity, it will leave a blank page and do nothing. but after I've changed it to be called only clicking a button, it showed me the error, and when I printed the stack-trace, i found in the logcat my real hash-key. after all, it was just a problem with the hash key, in windows the facebook instructions don't work well.

于 2012-10-03T09:16:25.013 回答