Search in sources :

Example 6 with Response

use of com.facebook.Response 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

Response (com.facebook.Response)6 Session (com.facebook.Session)6 Request (com.facebook.Request)5 GraphUser (com.facebook.model.GraphUser)5 GraphUserCallback (com.facebook.Request.GraphUserCallback)3 Bundle (android.os.Bundle)2 FacebookAuthorizationException (com.facebook.FacebookAuthorizationException)2 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)2 FacebookRequestError (com.facebook.FacebookRequestError)2 GraphUserListCallback (com.facebook.Request.GraphUserListCallback)2 GraphObject (com.facebook.model.GraphObject)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Random (java.util.Random)2 FacebookDialogException (com.facebook.FacebookDialogException)1 FacebookException (com.facebook.FacebookException)1 FacebookServiceException (com.facebook.FacebookServiceException)1 SessionState (com.facebook.SessionState)1 FacebookDialog (com.facebook.widget.FacebookDialog)1 WebDialog (com.facebook.widget.WebDialog)1 OnCompleteListener (com.facebook.widget.WebDialog.OnCompleteListener)1