代码之家  ›  专栏  ›  技术社区  ›  Sampath Kumar

在Android中,如果设备中已经安装了Facebook,为什么Facebook注册不起作用?

  •  0
  • Sampath Kumar  · 技术社区  · 12 年前

    我已尝试在应用程序中使用Facebook,这在未安装Facebook应用程序的设备上运行良好。但当设备上已经安装了Facebook时,这无法提供会话。

    public void facebookSignIn(CallbackContext callContext){
        try {
            isFacebookLogin = true;
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    mConnectionProgressDialog.show();               }
            });
            this.callbackContext = callContext;
            Session.openActiveSession(this, true, new Session.StatusCallback() {
                // callback when session changes state
                @Override
                public void call(Session session, SessionState state, Exception exception) {
                    Log.d("facebook","session open");
                    if (session.isOpened()) {
                        // make request to the /me API
                        Request.newMeRequest(session, new Request.GraphUserCallback() {
                            // callback after Graph API response with user object
                            @Override
                            public void onCompleted(GraphUser user, Response response) {
                                if (user != null) {
                                    String userID = user.getId();
                                    callbackContext.success(userID);
                                    Toast.makeText(MDLIVEMain.this, user.getName() + " is connected.", Toast.LENGTH_LONG).show();
                                } else {
                                    // TODO: handle exception
                                    callbackContext.error(MDLiveLocalizationSystem.localizedStringForKey("nat_authen_failure"));
                                }
                                getActivity().runOnUiThread(new Runnable() {
                                    public void run() {
                                        mConnectionProgressDialog.dismiss();
                                    }
                                });
                            }
    
                        }).executeAsync();
                    }
                }
            });
        }catch (Exception e){
            e.printStackTrace();
            callbackContext.error(MDLiveLocalizationSystem.localizedStringForKey("nat_authen_failure"));
            GATrackingExceptions.trackExceptions(e.getLocalizedMessage(), MDLIVEMain.this);
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    mConnectionProgressDialog.dismiss();
                }
            });
        }
    }
    

    这是一个activityResult代码

      @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
        try {
            CordovaPlugin callback = this.activityResultCallbacks;
            if (callback != null) {
                callback.onActivityResult(requestCode, responseCode, intent);
            }
            Log.d("isFacebookLogin",isFacebookLogin+"");
            if(isFacebookLogin){
                try {
                    isFacebookLogin = false;
                    Session.getActiveSession().onActivityResult(this, requestCode, responseCode, intent);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }else {
                if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) {
                    mConnectionResult = null;
                    mPlusClient.connect();
                }
    
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        mConnectionProgressDialog.dismiss();
                    }
                });
    
                if (requestCode == PASSCODE_RESULT_PAGE) {
                    if (responseCode == RESULT_OK) {
                        activityVisible = true;
                        this.callbackContext.success(intent.getExtras().getString("passcode_pin"));
                    } else {
                        this.callbackContext.success(intent.getExtras().getString("passcode_pin"));
                        isFromPasscodePage = true;
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Community Mohan Dere    9 年前

    我在这里回答了这类(fb的哈希)问题:

    Facebook Login and Post To Wall works for first time only

    注意:Fb给出了无效哈希的问题bcz,因此您必须生成有效哈希。