1

我的应用程序已经有一个登录程序,但如果我尝试使用 FB 登录,则尝试与 facebook graph api 集成,应用程序不接受。帮助我在这里粘贴 FB 按钮代码

case R.id.fbButton:
            authenticateOnFacebook();
            sendFacebookIdToServer(APP_ID, getApplicationContext());
            break;

facebook 的身份验证方法,在此我也使用 getcredentials 方法。

public void authenticateOnFacebook()
     {
        try{
            String[] permissions={"user_birthday", "email"};
            facebook.authorize(this.activity, permissions, Facebook.FORCE_DIALOG_AUTH, new DialogListener() {

                @Override
                public void onFacebookError(FacebookError e) {
                }

                @Override
                public void onError(DialogError e) {
                }

                @Override
                public void onComplete(Bundle values) {
                    try{
                        String facebookId = getCredentials((String) values.get("access_token"));
                        sendFacebookIdToServer(facebookId, context);
                    } catch(Exception e){
                        e.printStackTrace();
                    }
                }

                @Override
                public void onCancel() {

                }
            });
        } catch(Exception e){
            e.printStackTrace();
        }
     }

     protected String getCredentials(String token) {
        JSONObject jObject=null;
        String facebookId = null; 

        Bundle params = new Bundle();
        params.putString(Facebook.TOKEN, token);

        try {
            jObject = new JSONObject(facebook.request("me", params));
        }catch(Exception e){
            e.printStackTrace();
        }

        if(jObject!=null)
        {
            try {  
                facebookId = jObject.getString("id");
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        return facebookId;
    }

为了向我的服务器发送请求以进行身份​​验证,我正在使用这种方法

public void sendFacebookIdToServer(String facebookId, Context context){
        String accessToken = null;
        DatabaseHelper helper = new DatabaseHelper(context);
        DatabaseUtility dao = new DatabaseUtility(helper);
        try {
            accessToken = dao.getAccessToken();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        Map<String , String> params = new HashMap<String,String>();
        params.put(Constants.FACEBOOK_ID, facebookId);
        params.put(Constants.ACCESS_TOKEN_PARAM, accessToken);
        Status status = null;
        try {
            status = Utils.addFacebookAccount(params, context);
        } catch (NullPointerException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if((status != null) && (status.getStatus().equalsIgnoreCase(Constants.SUCCESS))){
            navigateNowLisnScreenWithSuccess();
        }
     }

    private void navigateNowLisnScreenWithSuccess() {
        // TODO Auto-generated method stub
        Intent i = new Intent(context,TabView.class);
        startActivity(i);   
    }

日志猫

01-16 21:40:26.098: E/Cursor(1299):     at android.view.View.performClick(View.java:2408)
01-16 21:40:26.108: E/Cursor(1299): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.lisnx.activity/databases/lisnx.db, table = access_token, query = SELECT token FROM access_token
01-16 21:40:26.108: E/Cursor(1299): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
01-16 21:40:26.108: E/Cursor(1299):     at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
01-16 21:40:26.108: E/Cursor(1299):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
01-16 21:40:26.108: E/Cursor(1299):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
01-16 21:40:26.108: E/Cursor(1299):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
01-16 21:40:26.108: E/Cursor(1299):     at com.lisnx.activity.LoginActivity.sendFacebookIdToServer(LoginActivity.java:223)
01-16 21:40:26.108: E/Cursor(1299):     at com.lisnx.activity.LoginActivity.onClick(LoginActivity.java:263)
01-16 21:40:26.108: E/Cursor(1299):     at android.view.View.performClick(View.java:2408)
01-16 21:40:26.108: E/Cursor(1299):     at android.view.View$PerformClick.run(View.java:8816)
01-16 21:40:26.108: E/Cursor(1299):     at android.os.Handler.handleCallback(Handler.java:587)
01-16 21:40:26.108: E/Cursor(1299):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-16 21:40:26.108: E/Cursor(1299):     at android.os.Looper.loop(Looper.java:123)
01-16 21:40:26.108: E/Cursor(1299):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-16 21:40:26.108: E/Cursor(1299):     at java.lang.reflect.Method.invokeNative(Native Method)
01-16 21:40:26.108: E/Cursor(1299):     at java.lang.reflect.Method.invoke(Method.java:521)
01-16 21:40:26.108: E/Cursor(1299):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-16 21:40:26.108: E/Cursor(1299):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-16 21:40:26.108: E/Cursor(1299):     at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0