Question

Hey can someone point me in the right direction of a good Facebook tutorial for android? The tutorial their developer site isnt all that good.

This is what i've came up with so far:

public static final int FBResultCode = 100;
private static Session.StatusCallback sharedFBStatusCallback = new Session.StatusCallback()
{
    @Override
    public void call(Session session, SessionState state, Exception exception)
    {
        if(exception != null)
            Log.e("fb error", exception.toString());
        switch(state)
        {
        case OPENED:
                            //login successful
            break;
        case CLOSED:
        case CLOSED_LOGIN_FAILED:
            closeFBSession();
            break;
        default:
            break;
        }
    }
};

public static void openFBSessionWithLoginUI(boolean loginUI)
{
    Session session = Session.getActiveSession();

    if (session != null && 
            !session.isOpened() && 
            !session.isClosed()) 
    {
        ArrayList<String> perms = new ArrayList<String>();
        perms.add("user_likes");
        perms.add("user_birthday");
        perms.add("read_friendlists");

        Session.OpenRequest openRequest = new Session.OpenRequest(rootActivity)
        .setCallback(sharedFBStatusCallback)
        .setDefaultAudience(SessionDefaultAudience.FRIENDS)
        .setLoginBehavior(loginUI? SessionLoginBehavior.SUPPRESS_SSO: SessionLoginBehavior.SSO_ONLY)
        .setRequestCode(FBResultCode)
        .setPermissions(perms);

        session.openForRead(openRequest);
    }
    else 
    {
        Session.openActiveSession(rootActivity, loginUI, sharedFBStatusCallback);
    }

}

private static void closeFBSession()
{
    Session currentSess = Session.getActiveSession();

    if(currentSess != null)
    {
        currentSess.closeAndClearTokenInformation();
    }
}

However this returns an error:

E/fb error(3601): java.lang.UnsupportedOperationException: Session: an attempt was made to open a session that has a pending request.

What am i doing wrong? Or better yet, what is the best way to handle fb logins?

Était-ce utile?

La solution

i have used this tutorial and worked properly:

http://www.androidhive.info/2012/03/android-facebook-connect-tutorial/

Theres also this one, wich is pretty detailed. https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

I also use this logic to log in with an existing token since in my app it always connects with the samer user as some sort of a host of events.

Android Facebook SDK - Get user events

Autres conseils

In addition to Gilson, this tutorial also very helpful for those who try to connect facebook into their android application.

http://ericosgood.com/prog/facebook-android-sdk-tutorial/

http://blog.doityourselfandroid.com/2011/02/28/30-minute-guide-integrating-facebook-android-application/

http://tutotialandroid.blogspot.com/2013/06/easy-facebook-android-sdk-simple.html

Androidhive is also such a useful link..

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top