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();
}
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();
}
Aggregations