Facebook团结sdk避免显示您已经授权此应用程序

时间:2014-05-13 12:54:11

标签: facebook-unity-sdk

如何避免显示您已使用Facebook Unity SDK授权此应用。使用空字符串调用FB.Login(string.Empty,LoginCallback)函数仍然会调用基本授权。

1 个答案:

答案 0 :(得分:0)

您尝试调用此方法,这将避免fb的基本授权...

    private void loginWithFB()
{

    //final Dialog d = ProgressDialog.showDialog((Activity)mContext, "Please Wait...");

     Log.d(TAG, "inside loginToFB");
     String GCM_ID = registraionID;
     Log.d(TAG, "inside loginToFB got gcm id :"+GCM_ID);
    SessionTracker mSessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() 
    {

        @Override
        public void call(Session session, SessionState state, Exception exception) 
        {
            Log.d(TAG, "loginToFB call");
        }
    }, null, false);

    //String applicationId = Utility.getMetadataApplicationId(getBaseContext());


    String applicationId = TagStrings.APP_ID;
    Log.d("Fb Login ID..", applicationId+"");
    Session mCurrentSession = mSessionTracker.getSession();
    Log.d(TAG, "loginToFB got currentsession");
    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) 
    {
        Log.d(TAG, "loginToFB curent session is bad creating new one");
        mSessionTracker.setSession(null);
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        Session.setActiveSession(session);
        mCurrentSession = session;
    }

    final Session mCurrentSessionFin = mCurrentSession;

    if (!mCurrentSession.isOpened()) 
    {
        Log.d(TAG, "loginToFB current session is closed");
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(LoginActivity.this);

        Log.d(TAG, "loginToFB session open req sent");
        if (openRequest != null) 
        {
            //openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location"));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
            openRequest.setRequestCode(220);
            mCurrentSession.openForRead(openRequest);
        }



        Log.d(TAG, "loginToFB reading user data from fb if ");
        Request request = Request.newMeRequest(mCurrentSession, 
                new Request.GraphUserCallback() 
        {



            @Override
            public void onCompleted(GraphUser user, Response response) 
            {
                 Log.d(TAG, "loginTo iside onCompleted callback");
                // If the response is successful
                if (mCurrentSessionFin == Session.getActiveSession()) 
                {
                     Log.d(TAG, "loginToFB current session is active session"); 
                    if (user != null) 
                    {
                         Log.d(TAG, "loginToFB user is not null");
                        // Set the id for the ProfilePictureView
                        // view that in turn displays the profile picture.
                         try 
                          {
                             updateUI(user);
                              Log.d(TAG, user.getId() + " " + user.getName() + " " + user.getInnerJSONObject());                         
                          } catch (Exception e) 
                          {
                              Log.d(TAG, "Exception:"+e.toString());

                          }
                    }else{
                         Log.d(TAG, "loginToFB user is null");
                    }
                }else{
                     Log.d(TAG, "loginToFB current session is not active session");
                }                           
                if (response.getError() != null) {
                    // Handle errors, will do so later.
                     Log.d(TAG, "Exception occured:"+response.getError().getErrorMessage());
                     Log.d(TAG, "Exception occured: detailed"+response.getError().toString());
                }
            }
        });
        request.executeAsync();

    }else 
    {               
        Log.d(TAG, "loginToFB reading user data from fb else");
        Request request = Request.newMeRequest(mCurrentSession, 
                new Request.GraphUserCallback() {
            @Override
            public void onCompleted(GraphUser user, Response response) {
                // If the response is successful
                if (mCurrentSessionFin == Session.getActiveSession()) 
                {
                    if (user != null) 
                    {
                        // Set the id for the ProfilePictureView
                        // view that in turn displays the profile picture.
                         try 
                          {
                             updateUI(user);
                              Log.d(TAG, user.getId() + " " + user.getName() + " " + user.getInnerJSONObject());

                          } catch (Exception e) 
                          {
                              Log.d(TAG, "Exception:"+e.toString());

                          }
                    }
                }
                if (response.getError() != null) {
                    // Handle errors, will do so later.
                     Log.d(TAG, "Exception        occured:"+response.getError().getErrorMessage());
                }
            }
        });
        request.executeAsync();
    }
}