Search in sources :

Example 46 with Session

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

the class ConnectPlugin method getResponse.

/**
     * Create a Facebook Response object that matches the one for the Javascript SDK
     * @return JSONObject - the response object
     */
public JSONObject getResponse() {
    String response;
    final Session session = Session.getActiveSession();
    if (checkActiveSession(session)) {
        Date today = new Date();
        long expiresTimeInterval = (session.getExpirationDate().getTime() - today.getTime()) / 1000L;
        long expiresIn = (expiresTimeInterval > 0) ? expiresTimeInterval : 0;
        response = "{" + "\"status\": \"connected\"," + "\"authResponse\": {" + "\"accessToken\": \"" + session.getAccessToken() + "\"," + "\"expiresIn\": \"" + expiresIn + "\"," + "\"session_key\": true," + "\"sig\": \"...\"," + "\"userID\": \"" + userID + "\"" + "}" + "}";
    } else {
        response = "{" + "\"status\": \"unknown\"" + "}";
    }
    try {
        return new JSONObject(response);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return new JSONObject();
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Date(java.util.Date) Session(com.facebook.Session)

Example 47 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)

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