Facebook Sample Session Login Applicatiom not work

2019-04-17 07:05发布

问题:

If the phone already has facebook native application installed it go to that application after giving the user name and passowrd it start loading and show pop telling complete action using browser when click the browser it says web page not available.

the web page at fbconnect://success#sucess_token=CAA.. might be temporarli down or it may have moved permenantly to a new web address. There is no callback called to the application.

I have created the hash key properly my application SSO work fine in the SDK version 2.0. So it can't be hash key mismatch. When the application SessionLoginBehavior.SUPPRESS_SSO mode it works as expected.

OpenRequest req=new OpenRequest(LoginActivity.this);
req.setPermissions(Arrays.asList("read_stream", "user_birthday","email"));
session.openForRead(req.setCallback(statusCallback));

Is there way to implement SSO behavior using session login mechanism? I have search every where i didn't find an answer. When the Native facebook application there it start to failed.

回答1:

You can use it like this...

mBtnFacebook = (LoginButton) v.findViewById(R.id.btn_facebook);
mBtnFacebook.setReadPermissions(Arrays.asList("email", "user_birthday"));
mBtnFacebook.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

and then

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode != 0) {
            Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
            Session.openActiveSession(this, true, new Session.StatusCallback() {
                @Override
                public void call(final Session session, SessionState state, Exception exception) {
                    if (session.isOpened()) {
                        Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                            @Override
                            public void onCompleted(GraphUser user, Response response) {
                                if (user != null) {

                                }
                            }
                        });
                    } 
                }
            });
        }
    }

Make sure you have this in manifest

<activity android:name="com.facebook.LoginActivity"
          android:screenOrientation="portrait"
          android:theme="@android:style/Theme.Translucent.NoTitleBar"
          android:label="@string/app_name" />

as well as

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>

this tag is inside tag

that should be it :)



回答2:

to generate hash key use this code.

try {
            PackageInfo info = getPackageManager().getPackageInfo(
                    "com.facebook.scrumptious", PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.d("YOURHASH KEY:",
                        Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (NameNotFoundException e) {

        } catch (NoSuchAlgorithmException e) {

        }

thanks.