【问题标题】:Facebook SDK 3.0:How to remove "you have already authorized to this app" screenFacebook SDK 3.0:如何删除“您已授权此应用”屏幕
【发布时间】:2013-07-11 01:11:25
【问题描述】:

我在我的 Android 应用中使用 Facebook,它运行良好。

但是,我意识到每次登录时都会出现无用的屏幕,并使用“确定”和“取消”选项说“您已经授权此应用程序”。

如何避免或从我的应用中移除此屏幕。

我在 Google 上搜索了一些旧版 Facebook SDK 的答案,但是如何使用新版 Facebook SDK(3.0 及更高版本)实现它?

这是我的代码,

public void onClick(View v)
        {

            Bundle myParams = new Bundle();
            myParams.putString("message", " DOWNLOAD THE 'Saragama' ANDROID APP FROM " + url_android.toString()
                    + ". Fully integrated with Facebook and Twitter.");

            myParams.putString("name", mSharingText.getText().toString());
            myParams.putString("caption", "www.saragama.com");
            myParams.putString("description", "Various religios music, chants, mantras, christian songs, islamic music, quran and more on saragama");
            myParams.putString("link", "http://android.saragama.com");
            myParams.putString("picture", albumImageURL);

            if (PlusUtilities.isInternetConnected())
                {
                    // ~post your data
                    Session session = Session.getActiveSession();
                    if (session != null)
                        {
                            MyLog.w("session state", session.getState().toString());
                            if (session.getState().equals(SessionState.OPENED) || session.getState().equals(SessionState.OPENED_TOKEN_UPDATED))
                                {
                                    publishStory(myParams);
                                }
                            else
                                {
                                    plusUtilities1.showAlertDialog("Please login first!");
                                }
                        }
                    else
                        {
                            plusUtilities1.showAlertDialog("Please login first!");
                        }

                }
            else
                {
                    plusUtilities1.showAlertDialog("Problem occured with your internet connection!");
                }
        }

    // Facebook Login-------------------------------------------------------------------------------------
    private void loginToFacebook()
        {
            if (PlusUtilities.isInternetConnected())
                {
                    Session session = Session.getActiveSession();

                    // if session is in exceptional state
                    if (session.getState() == SessionState.CLOSED_LOGIN_FAILED || session.getState() == SessionState.OPENING)
                        {
                            session.closeAndClearTokenInformation();
                        }

                    if (!session.isOpened() && !session.isClosed())
                        {
                            String[] PERMISSION_ARRAY_PUBLISH =
                                {"publish_actions" };
                            List<String> PERMISSION_LIST = Arrays.asList(PERMISSION_ARRAY_PUBLISH);
                            session.openForPublish(new Session.OpenRequest(FacebookActivity.this).setPermissions(PERMISSION_LIST).setCallback(
                                    statusCallback1));
                        }
                    else
                        {
                            Session.openActiveSession(this, true, statusCallback1);
                        }
                }
            else
                {
                    plusUtilities1.showAlertDialog("Please check your internet connection!");
                }
        }

    @Override
    protected void onSaveInstanceState(Bundle outState)
        {
            super.onSaveInstanceState(outState);
            Session session = Session.getActiveSession();
            Session.saveSession(session, outState);
        }

    @Override
    protected void onActivityResult(int requestCode, int responseCode, Intent data)
        {

            super.onActivityResult(requestCode, responseCode, data);

            // plusUtilities1.ShowToast("onActivityResult");
            MyLog.i("onActivityResult requestCode :responsecode:session state", requestCode + ":" + responseCode + ":"
                    + Session.getActiveSession().getState().toString());
            switch (requestCode)
                {

                case MyRaagaLoginActivity.REQUEST_CODE_FACEBOOK_LOGIN:
                    if (responseCode == RESULT_OK)
                        {
                                    MyLog.e("Login", "trying to facebook Login");
                                    Session.getActiveSession().onActivityResult(Act1, requestCode, responseCode, data);

                        }
                    else
                        {
                            plusUtilities1.ShowToast("User access denied!");
                        }
                    break;

                default:
                    MyLog.i("case:", "default");
                    break;
                }

        }

    /**
     * function to get active facebook session if already exist or create the new session
     * 
     * @param savedInstanceState
     *            =check if Session exist and restored in bundle during onSaveInstanceState() system call
     * @author DeepakD
     */
    public void GetOrCreateFacebookActiveSession(Bundle savedInstanceState)
        {
            Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
            Settings.addLoggingBehavior(LoggingBehavior.REQUESTS);

            Session session = Session.getActiveSession();

            // if session is null try to find if session is saved previously
            if (session == null)
                {
                    if (savedInstanceState != null)
                        {
                            session = Session.restoreSession(this, null, statusCallback1, savedInstanceState);
                        }

                    // if still session is null then create the new session
                    if (session == null)
                        {
                            session = new Session(this);
                        }

                    // set the created session as active session
                    Session.setActiveSession(session);

                }
            updateFBbutton();
        }

    /**
     * set login or logout button
     */
    private void updateFBbutton()
        {

            Session session = Session.getActiveSession();
            if (session.isOpened())
                {
                    FbLoginbtn.setText("FBLogout");
                    FbLoginbtn.setOnClickListener(new OnClickListener()
                        {
                            public void onClick(View view)
                                {
                                    onClickFBLogout();
                                }
                        });
                }
            else
                {
                    FbLoginbtn.setText("FBLogin");
                    FbLoginbtn.setOnClickListener(new OnClickListener()
                        {
                            public void onClick(View view)
                                {
                                    loginToFacebook();
                                }
                        });
                }

        }

    /**
     * Logout from facebook
     */
    private void onClickFBLogout()
        {
            Session session = Session.getActiveSession();
            if (!session.isClosed())
                {
                    session.closeAndClearTokenInformation();
                    plusUtilities1.ShowToast("Logout successful");
                }
        }

    /**
     * This class is used to fetch the current status of active session
     * 
     * @author DeepakD
     * 
     */
    private class SessionStatusCallback1 implements Session.StatusCallback
        {
            @Override
            public void call(Session session, SessionState state, Exception exception)
                {

                    updateFBbutton();
                    plusUtilities1.DissmissPD();
                    MyLog.w("session state", session.getState().toString());

                    if(session.getState()==SessionState.CLOSED_LOGIN_FAILED)
                        {
                            //login failed
                            plusUtilities1.ShowToast("Unable to connect,please try later..");
                            session.closeAndClearTokenInformation();
                        }

                    if (session.getState()== SessionState.OPENED)
                        {
                            //login successful
                            plusUtilities1.ShowToast("Login successful");
                        }
                }

        }


    /**
     * actually post the data on facebook
     * 
     * @param myParams
     *            Bundle of parameters to be post
     */
    private void publishStory(Bundle myParams)
        {
            plusUtilities1.ShowPD("Sharing data...");
            Session session = Session.getActiveSession();

            if (session != null)
                {

                    // Check for publish permissions
                    List<String> permissions = session.getPermissions();
                    try
                        {
                            if (!isSubsetOf(PERMISSIONS, permissions))
                                {
                                    Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS);
                                    session.requestNewPublishPermissions(newPermissionsRequest);
                                }
                        }
                    catch (Exception e1)
                        {
                            // TODO Auto-generated catch block
                            e1.printStackTrace();
                        }

                    Request.Callback callback = new Request.Callback()
                        {
                            public void onCompleted(Response response)
                                {
                                    plusUtilities1.DissmissPD();

                                    MyLog.w("post response", "" + response.toString());
                                    if (response.getError() == null)
                                        {
                                            JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                                            String postId = null;
                                            try
                                                {
                                                    postId = graphResponse.getString("id");
                                                }
                                            catch (JSONException e)
                                                {

                                                    Toast.makeText(FacebookActivity.this, "JSON error " + e.getMessage(), Toast.LENGTH_LONG)
                                                            .show();

                                                }
                                            catch (Exception e)
                                                {
                                                    e.printStackTrace();
                                                    Toast.makeText(FacebookActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
                                                }
                                            FacebookRequestError error = response.getError();
                                            Log.e("post response", response.toString());
                                            if (error != null)
                                                {
                                                    Toast.makeText(FacebookActivity.this, error.getErrorMessage(), Toast.LENGTH_SHORT).show();
                                                }
                                            else
                                                {
                                                    Toast.makeText(FacebookActivity.this, "Posted successfully!",
                                                            Toast.LENGTH_LONG).show();
                                                    FlurryAgent.logEvent("Audio Facebook share -" + EventName);
                                                }
                                        }
                                    else
                                        {
                                            plusUtilities1.showAlertDialog("Something went wrong while posting!");
                                        }
                                }
                        };

                    MyLog.w("BUNDLE TO BE POSTED;", myParams.toString());
                    Request request = new Request(session, "/me/feed", myParams, HttpMethod.POST, callback);
                    RequestAsyncTask task = new RequestAsyncTask(request);
                    task.execute();
                }

        }

    public static boolean isSubsetOf(Collection<String> subset, Collection<String> superset)
        {
            for (String string : subset)
                {
                    if (!superset.contains(string))
                        {
                            return false;
                        }
                }
            return true;
        }

    protected void onStart()
        {

            super.onStart();
            MyLog.i("FacebookActivity", "onStart");
            FlurryAgent.onStartSession(this, KeysCls.Flurry_Analytics_Key);
            FlurryAds.displayAd(this, "AppCircle_Ads", linlayAdLayout);

            if (PlusUtilities.isInternetConnected())
                {
                    Session.getActiveSession().addCallback(statusCallback1);

                }
            else
                {
                    plusUtilities1.showAlertDialog("Please check your internet connection and try again!");
                }
        }

    /**
     * convert post's simple text to text with links
     * 
     * @param Name
     * @param Link
     * @return
     */
    String wallpostWithLink(String Name, String Link)
        {

            jo = new JSONObject();
            try
                {

                    jo.put("name", Name);
                    jo.put("link", Link);
                }
            catch (Exception e)
                {
                    e.printStackTrace();
                }

            return jo.toString();
        }

    @Override
    protected void onStop()
        {
            super.onStop();
            FlurryAgent.onEndSession(this);
        }

【问题讨论】:

  • 您需要删除您的用户登录数据吗?
  • 不,我只是想删除成功登录后出现的“您已授权此应用”的屏幕
  • 发布您的代码我会在一分钟内说出来。可能是因为Toast 声明。
  • 我已经发布了代码(对不起,它很乱)
  • 因为Session。您已经登录,所以它看起来像这样。只需按照以下步骤操作:转到 Settings -> Apps -> 选择 APP -> 单击 Clear Data

标签: android facebook facebook-graph-api oauth


【解决方案1】:

转到developers.facebook.comSettings-&gt; Basic-&gt;Single Sign On -&gt; YES

【讨论】:

    【解决方案2】:

    在 facebook sdk 4.0 中尝试像这样在 onResume 和 onPause 中激活和停用应用程序:

    @Override
    protected void onResume() {
        super.onResume();
    
        // update your UI
    
        // Logs 'install' and 'app activate' App Events.
        AppEventsLogger.activateApp(this);
    }
    
    @Override
    protected void onPause() {
        super.onPause();
    
        // Logs 'app deactivate' App Event.
        AppEventsLogger.deactivateApp(this);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-10
      • 1970-01-01
      相关资源
      最近更新 更多