Search in sources :

Example 41 with Session

use of com.facebook.Session in project phonegap-facebook-plugin by Wizcorp.

the class ConnectPlugin method makeGraphCall.

private void makeGraphCall() {
    Session session = Session.getActiveSession();
    Request.Callback graphCallback = new Request.Callback() {

        @Override
        public void onCompleted(Response response) {
            if (graphContext != null) {
                if (response.getError() != null) {
                    graphContext.error(getFacebookRequestErrorResponse(response.getError()));
                } else {
                    GraphObject graphObject = response.getGraphObject();
                    graphContext.success(graphObject.getInnerJSONObject());
                }
                graphPath = null;
                graphContext = null;
            }
        }
    };
    //If you're using the paging URLs they will be URLEncoded, let's decode them.
    try {
        graphPath = URLDecoder.decode(graphPath, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    String[] urlParts = graphPath.split("\\?");
    String graphAction = urlParts[0];
    Request graphRequest = Request.newGraphPathRequest(null, graphAction, graphCallback);
    Bundle params = graphRequest.getParameters();
    if (urlParts.length > 1) {
        String[] queries = urlParts[1].split("&");
        for (String query : queries) {
            int splitPoint = query.indexOf("=");
            if (splitPoint > 0) {
                String key = query.substring(0, splitPoint);
                String value = query.substring(splitPoint + 1, query.length());
                params.putString(key, value);
            }
        }
    }
    params.putString("access_token", session.getAccessToken());
    graphRequest.setParameters(params);
    graphRequest.executeAsync();
}
Also used : Response(com.facebook.Response) GraphUserCallback(com.facebook.Request.GraphUserCallback) Bundle(android.os.Bundle) Request(com.facebook.Request) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GraphObject(com.facebook.model.GraphObject) Session(com.facebook.Session)

Example 42 with Session

use of com.facebook.Session in project openkit-android by OpenKit.

the class FBLoginRequest method openCachedFBSession.

public void openCachedFBSession(Context ctx) {
    Session cachedSession = Session.openActiveSessionFromCache(ctx);
    if (cachedSession != null) {
        Session.setActiveSession(cachedSession);
        OKLog.v("Opened cached FB Session");
    } else {
        OKLog.v("Did not find cached FB session");
    }
}
Also used : Session(com.facebook.Session)

Example 43 with Session

use of com.facebook.Session in project openkit-android by OpenKit.

the class FBLoginRequest method onSaveInstanceState.

public void onSaveInstanceState(Bundle outState) {
    Session session = Session.getActiveSession();
    Session.saveSession(session, outState);
}
Also used : Session(com.facebook.Session)

Example 44 with Session

use of com.facebook.Session in project openkit-android by OpenKit.

the class SessionTracker method setSession.

/**
     * Set the Session object to track.
     * 
     * @param newSession the new Session object to track
     */
public void setSession(Session newSession) {
    if (newSession == null) {
        if (session != null) {
            // We're current tracking a Session. Remove the callback
            // and start tracking the active Session.
            session.removeCallback(callback);
            session = null;
            addBroadcastReceiver();
            if (getSession() != null) {
                getSession().addCallback(callback);
            }
        }
    } else {
        if (session == null) {
            // We're currently tracking the active Session, but will be
            // switching to tracking a different Session object.
            Session activeSession = Session.getActiveSession();
            if (activeSession != null) {
                activeSession.removeCallback(callback);
            }
            broadcastManager.unregisterReceiver(receiver);
        } else {
            // We're currently tracking a Session, but are now switching 
            // to a new Session, so we remove the callback from the old 
            // Session, and add it to the new one.
            session.removeCallback(callback);
        }
        session = newSession;
        session.addCallback(callback);
    }
}
Also used : Session(com.facebook.Session)

Example 45 with Session

use of com.facebook.Session in project openkit-android by OpenKit.

the class ScoreCreator method CreateGlobalScores.

public static void CreateGlobalScores(int aNumScores, int aLeaderboardID, final int maxScoreValue) {
    final int numScores = aNumScores;
    final int leaderboardID = aLeaderboardID;
    OKLog.d("Getting list of FB friends");
    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        Request friendsRequest = Request.newMyFriendsRequest(session, new GraphUserListCallback() {

            @Override
            public void onCompleted(List<GraphUser> users, Response response) {
                FacebookRequestError error = response.getError();
                if (error != null) {
                    OKLog.d("Error getting Facebook friends");
                //requestHandler.onFail(error);
                } else {
                    OKLog.d("Got %d facebook friends", users.size());
                    Random generator = new Random();
                    for (int x = 0; x < numScores; x++) {
                        int friendIndex = generator.nextInt(users.size());
                        CreateScoreForFBUser(users.get(friendIndex), leaderboardID, x, maxScoreValue);
                    }
                }
            }
        });
        friendsRequest.executeAsync();
    } else {
        OKLog.v("FB session not open");
    }
}
Also used : Response(com.facebook.Response) GraphUser(com.facebook.model.GraphUser) Random(java.util.Random) GraphUserListCallback(com.facebook.Request.GraphUserListCallback) Request(com.facebook.Request) FacebookRequestError(com.facebook.FacebookRequestError) Session(com.facebook.Session)

Aggregations

Session (com.facebook.Session)47 KlyphSession (com.abewy.android.apps.klyph.core.KlyphSession)16 Response (com.facebook.Response)6 FacebookException (com.facebook.FacebookException)5 Request (com.facebook.Request)5 GraphUser (com.facebook.model.GraphUser)5 FacebookAuthorizationException (com.facebook.FacebookAuthorizationException)4 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)4 SessionState (com.facebook.SessionState)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 JSONException (org.json.JSONException)4 Bundle (android.os.Bundle)3 SpannableString (android.text.SpannableString)3 FacebookDialogException (com.facebook.FacebookDialogException)3 FacebookServiceException (com.facebook.FacebookServiceException)3 GraphUserCallback (com.facebook.Request.GraphUserCallback)3 FacebookRequestError (com.facebook.FacebookRequestError)2 GraphUserListCallback (com.facebook.Request.GraphUserListCallback)2 SessionTracker (com.facebook.internal.SessionTracker)2 GraphObject (com.facebook.model.GraphObject)2