本文整理汇总了Java中com.facebook.Session类的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于com.facebook包,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logout
import com.facebook.Session; //导入依赖的package包/类
public static void logout(Context ctx){
userFacebookAccessToken = null;
if (Session.getActiveSession() != null)
{
Session.getActiveSession().closeAndClearTokenInformation();
}
else
{
if (DEBUG) Timber.e("getActiveSessionIsNull");
Session session = Session.openActiveSessionFromCache(ctx);
if (session != null)
session.closeAndClearTokenInformation();
}
}
示例2: getUserFriendList
import com.facebook.Session; //导入依赖的package包/类
public static Promise<List<GraphUser>, BError, Void> getUserFriendList(){
final Deferred<List<GraphUser>, BError, Void> deferred = new DeferredObject<>();
if (!Session.getActiveSession().getState().isOpened())
{
return deferred.reject(new BError(BError.Code.SESSION_CLOSED));
}
Request req = Request.newMyFriendsRequest(Session.getActiveSession(), new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users, Response response) {
deferred.resolve(users);
}
});
req.executeAsync();
return deferred.promise();
}
示例3: openSession
import com.facebook.Session; //导入依赖的package包/类
private void openSession(String applicationId, List<String> permissions,
SessionLoginBehavior behavior, int activityCode, SessionAuthorizationType authType) {
if (sessionTracker != null) {
Session currentSession = sessionTracker.getSession();
if (currentSession == null || currentSession.getState().isClosed()) {
Session session = new Session.Builder(getActivity()).setApplicationId(applicationId).build();
Session.setActiveSession(session);
currentSession = session;
}
if (!currentSession.isOpened()) {
Session.OpenRequest openRequest = new Session.OpenRequest(this).
setPermissions(permissions).
setLoginBehavior(behavior).
setRequestCode(activityCode);
if (SessionAuthorizationType.PUBLISH.equals(authType)) {
currentSession.openForPublish(openRequest);
} else {
currentSession.openForRead(openRequest);
}
}
}
}
示例4: createRequest
import com.facebook.Session; //导入依赖的package包/类
private Request createRequest(String userID, Set<String> extraFields, Session session) {
Request request = Request.newGraphPathRequest(session, userID + "/friends", null);
Set<String> fields = new HashSet<String>(extraFields);
String[] requiredFields = new String[]{
ID,
NAME
};
fields.addAll(Arrays.asList(requiredFields));
String pictureField = adapter.getPictureFieldSpecifier();
if (pictureField != null) {
fields.add(pictureField);
}
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
示例5: startLogin
import com.facebook.Session; //导入依赖的package包/类
private void startLogin(GraphUser user, Session session) {
try {
loginMode = true;
Fragment fragment = new FragmentSignIn();
Bundle args = new Bundle();
args.putInt(FragmentSignIn.LOGIN_MODE_ARG, LoginActivity.Mode.FACEBOOK.ordinal());
args.putString(FragmentSignIn.LOGIN_PASSWORD_OR_TOKEN_ARG, session.getAccessToken());
args.putString(FragmentSignIn.LOGIN_USERNAME_ARG, (String) user.getProperty("email"));
fragment.setArguments(args);
getChildFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, "tag").setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();
Analytics.SocialTimeline.login();
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: requestUserData
import com.facebook.Session; //导入依赖的package包/类
public void requestUserData( Session session ) {
// Request user data and show the results
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
User currentUser = new User();
currentUser.setUserId(user.getId());
currentUser.setUserName(user.getUsername());
currentUser.setFirstName(user.getFirstName());
currentUser.setLastName(user.getLastName());
currentUser.setDisplayName(user.getName());
currentUser.setMail((String) user.getProperty("email"));
currentUser.setProviderDisplayName("Facebook");
currentUser.setProvider(PROVIDER_NAME);
FbLoginDelegate.this.mUserHelper.setCurrentUser(currentUser);
if ( mUserSessionCallback != null) {
mUserSessionCallback.onLogin();
}
}
}
}).executeAsync();
}
示例7: onSessionStateChange
import com.facebook.Session; //导入依赖的package包/类
/**
* Changes the UI when an interaction with the Session object occurs with the user.
* @param session The current active Session.
* @param sessionState The current state of the active Session.
* @param e An Exception if there is one.
*/
private void onSessionStateChange(Session session, SessionState sessionState, Exception e) {
if (sessionState == SessionState.OPENED) {
Log.d(TAG, "Successful login!");
new Request(session, "/me", null, HttpMethod.GET, new Request.Callback() {
@Override
public void onCompleted(Response response) {
JSONObject obj = response.getGraphObject().getInnerJSONObject();
Log.d(TAG, "Got back " + obj + " from Facebook API.");
UserSession.getInstance().setFacebookData(obj);
getUserData();
}
}).executeAsync();
} else if (e != null) { // handle exception
}
}
示例8: ensureOpenSession
import com.facebook.Session; //导入依赖的package包/类
private boolean ensureOpenSession() {
if (Session.getActiveSession() == null
|| !Session.getActiveSession().isOpened()) {
Session.openActiveSession(this, true, PERMISSIONS,
new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
onSessionStateChanged(session, state, exception);
}
});
return false;
}
makeMeRequest();
return true;
}
示例9: sendRequestDialog
import com.facebook.Session; //导入依赖的package包/类
private void sendRequestDialog() {
Bundle params = new Bundle();
params.putString("title", "Solicitação de Aplicativo");
params.putString("message", "Experimente o IPRJapp");
params.putString("link","https://play.google.com/store/apps/details?id=com.wb.goog.batman.brawler2013");
params.putString("data",
"{\"badge_of_awesomeness\":\"1\"," +
"\"social_karma\":\"5\"}");
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(this.getActivity(), Session.getActiveSession(), params))
.setOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
}
})
.build();
requestsDialog.show();
}
示例10: updateView
import com.facebook.Session; //导入依赖的package包/类
private void updateView() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
makeMeRequest();
// textInstructionsOrLink.setText(URL_PREFIX_FRIENDS +
// session.getAccessToken());
// buttonLoginLogout.setText("Logout");
// buttonLoginLogout.setOnClickListener(new OnClickListener() {
// public void onClick(View view) { onClickLogout(); }
// });
} else {
onClickLogin();
// textInstructionsOrLink.setText("Please login");
// buttonLoginLogout.setText("Login");
// buttonLoginLogout.setOnClickListener(new OnClickListener() {
// public void onClick(View view) { onClickLogin(); }
// });
}
}
示例11: connect
import com.facebook.Session; //导入依赖的package包/类
@Override
public void connect(Activity activity)
{
Session session = Session.getActiveSession();
// TODO: I think we should validate the session here, but to what
// extent?
MadFacebookStatusCallback statusCallback =
new MadFacebookStatusCallback();
// Check if the session is already open.
if (!session.isOpened() && !session.isClosed())
{
OpenRequest openRequest = new OpenRequest(activity);
session.openForRead(openRequest
.setCallback(statusCallback));
}
else
{
Session.openActiveSession(activity, true,
statusCallback);
}
}
示例12: populateContact
import com.facebook.Session; //导入依赖的package包/类
public void populateContact() {
final Session session = Session.getActiveSession();
new Request(session, "/me/friends", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
// Process the returned response
GraphObject graphObject = response.getGraphObject();
if (graphObject != null) {
// Check if there is extra data
if (graphObject.getProperty("data") != null) {
JSONArray arrayObject = (JSONArray) graphObject
.getProperty("data");
int count = arrayObject.length();
if(count == 0)
hasAppFriends = false;
// Ensure the user has at least one friend
//session.close();
}
}
}
}).executeAsync();
}
示例13: SessionTracker
import com.facebook.Session; //导入依赖的package包/类
/**
* Constructs a SessionTracker to track the Session object passed in.
* If the Session is null, then it will track the active Session instead.
*
* @param context the context object.
* @param callback the callback to use whenever the Session's state changes
* @param session the Session object to track
* @param startTracking whether to start tracking the Session right away
*/
public SessionTracker(Context context, Session.StatusCallback callback, Session session, boolean startTracking) {
this.callback = new CallbackWrapper(callback);
this.session = session;
this.receiver = new ActiveSessionBroadcastReceiver();
this.broadcastManager = LocalBroadcastManager.getInstance(context);
if (startTracking) {
startTracking();
}
}
示例14: getOpenSession
import com.facebook.Session; //导入依赖的package包/类
/**
* Returns the current Session that's being tracked if it's open,
* otherwise returns null.
*
* @return the current Session if it's open, otherwise returns null
*/
public Session getOpenSession() {
Session openSession = getSession();
if (openSession != null && openSession.isOpened()) {
return openSession;
}
return null;
}
示例15: setSession
import com.facebook.Session; //导入依赖的package包/类
/**
* 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);
}
}