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