Java 类com.facebook.Session.StatusCallback 实例源码

项目:QuizUpWinner    文件:FacebookFriendsFragment.java   
private void connectFacebook()
{
  if ((Session.getActiveSession() != null) && (Session.getActiveSession().isOpened()))
  {
    int i;
    if (!TextUtils.isEmpty(QuizApplication.ˊ.ˋ.))
      i = 1;
    else
      i = 0;
    if (i != 0)
    {
      requestFriendPermission(Session.getActiveSession());
      return;
    }
  }
  Session.StatusCallback local2 = new Session.StatusCallback()
  {
    public void call(Session paramAnonymousSession, SessionState paramAnonymousSessionState, Exception paramAnonymousException)
    {
      FacebookFriendsFragment.this.onLoginFacebookCallback(paramAnonymousSession);
    }
  };
  Session.openActiveSession(getActivity(), this, true, local2);
}
项目:QuizUpWinner    文件:FacebookFriendsFragment.java   
private void requestFriendPermission(Session paramSession)
{
  Session.NewPermissionsRequest localNewPermissionsRequest = new Session.NewPermissionsRequest(this, Arrays.asList(new String[] { "user_friends" }));
  localNewPermissionsRequest.setCallback(new Session.StatusCallback()
  {
    public void call(Session paramAnonymousSession, SessionState paramAnonymousSessionState, Exception paramAnonymousException)
    {
      if (FacebookFriendsFragment.hasFriendsPermission(paramAnonymousSession.getPermissions()))
      {
         localί = ((FriendsTabActivity)FacebookFriendsFragment.this.getActivity()).getErrorDialog();
        localί.ʼ.removeView(localί.ʻ);
        localί.ˊ();
        FacebookFriendsFragment.this.getFriendsFromFacebook(paramAnonymousSession);
      }
    }
  });
  paramSession.requestNewReadPermissions(localNewPermissionsRequest);
}
项目:DualRunner    文件:FBLogin.java   
public static void init(String appID) {
    Session session;
    if (FB.isLoggedIn()) {
        session = Session.getActiveSession();
        // this shouldn't be an issue for most people: the app id in the session not matching the one provided
        // instead it can probably happen if a developer wants to switch app ids at run time.
        if (appID != session.getApplicationId()) {
            Log.w(FB.TAG, "App Id in active session ("+ session.getApplicationId() +") doesn't match App Id passed in: " + appID);
            session = new Builder(FB.getUnityActivity()).setApplicationId(appID).build();
        }
    } else {
        session = new Builder(FB.getUnityActivity()).setApplicationId(appID).build();
    }
    Session.setActiveSession(session);

    final UnityMessage unityMessage = new UnityMessage("OnInitComplete");
    unityMessage.put("key_hash", FB.getKeyHash());

    // if there is an existing session, reopen it
    if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState())) {
        Session.StatusCallback finalCallback = getFinalCallback(unityMessage, null);
        sessionOpenRequest(session, finalCallback, FB.getUnityActivity(), null, false);
    } else {
        unityMessage.send();
    }
}
项目:scoreflex-android-sdk    文件:ScoreflexFacebookWrapper.java   
public static void login(Activity activity, final SocialCallback callback)
        throws ScoreflexFacebookWrapper.FacebookException {
    if (!isFacebookAvailable(activity))
        throw new ScoreflexFacebookWrapper.FacebookException(
                "Facebook SDK is not available");

    try {
        Session.openActiveSession(activity, true, new Session.StatusCallback() {

            @Override
            public void call(Session session, SessionState state,
                    Exception exception) {
                String accessToken = null;
                if (null != session && session.isOpened())
                    accessToken = session.getAccessToken();
                callback.call(accessToken, exception);
            }
        });
    } catch (Exception e) {
        throw new FacebookException(e);
    }
}
项目:scoreflex-android-sdk    文件:ScoreflexFacebookWrapper.java   
private static void showDialogWithoutNotificationBar(final Activity activity, 
        final String action, final Bundle params, final SocialShareCallback callback) {
    Session fbSession = Session.openActiveSessionFromCache(activity);
    if (fbSession == null) {
        Session.openActiveSession(activity, true,
                new StatusCallback() {
                    @Override
                    public void call(Session session, SessionState state,
                            Exception exception) {
                        if (null != session && session.isOpened()) {
                            showDialog(activity, session, action, params, callback);
                        }
                    }
                });
    } else {
        showDialog(activity, fbSession, action, params, callback);
    }
}
项目:aquaplay    文件:FB.java   
private static OpenRequest getOpenRequest(StatusCallback callback, List<String> permissions) {
    OpenRequest req = new OpenRequest(getActivity());
    req.setCallback(callback);
    req.setPermissions(permissions);
    req.setDefaultAudience(SessionDefaultAudience.FRIENDS);

    return req;
}
项目:aquaplay    文件:FB.java   
private static Session.NewPermissionsRequest getNewPermissionsRequest(Session session, StatusCallback callback, List<String> permissions) {
    Session.NewPermissionsRequest req = new Session.NewPermissionsRequest(getActivity(), permissions);
    req.setCallback(callback);
    // This should really be "req.setCallback(callback);"
    // Unfortunately the current underlying SDK won't add the callback when you do it that way
    // TODO: when upgrading to the latest see if this can be "req.setCallback(callback);"
    // if it still doesn't have it, file a bug!
    session.addCallback(callback);
    req.setDefaultAudience(SessionDefaultAudience.FRIENDS);
    return req;
}
项目:QuizUpWinner    文件:SettingsFragment.java   
public void onFacebookLinkClick()
{
  if (!.ˋ("PREF_IS_FACEBOOK_LINKED"))
  {
    Session.openActiveSession(getActivity(), this, true, new Session.StatusCallback()
    {
      public void call(final Session paramAnonymousSession, SessionState paramAnonymousSessionState, Exception paramAnonymousException)
      {
        if (paramAnonymousSession.isOpened())
          Request.executeMeRequestAsync(paramAnonymousSession, new Request.GraphUserCallback()
          {
            public void onCompleted(GraphUser paramAnonymous2GraphUser, Response paramAnonymous2Response)
            {
              if (paramAnonymous2GraphUser != null)
              {
                SettingsFragment.access$002(SettingsFragment.this, paramAnonymousSession.getAccessToken());
                Object[] arrayOfObject = new Object[1];
                arrayOfObject[0] = SettingsFragment.this.fbAccessToken;
                .ˊ("REQUEST_FB_LINKING", arrayOfObject);
              }
            }
          });
      }
    });
    return;
  }
   localⅹ = QuizApplication.ˊ.ˋ;
  int i;
  if ((localⅹ.ˏ != null) && (!localⅹ.ˏ.equals("")))
    i = 1;
  else
    i = 0;
  if (i != 0)
  {
    .ˊ("REQUEST_FB_UNLINK", new Object[0]);
    return;
  }
  showUnlinkNotAllowedError();
}
项目:QuizUpWinner    文件:SessionTracker.java   
public SessionTracker(Context paramContext, Session.StatusCallback paramStatusCallback, Session paramSession, boolean paramBoolean)
{
  this.callback = new CallbackWrapper(paramStatusCallback);
  this.session = paramSession;
  this.receiver = new ActiveSessionBroadcastReceiver(null);
  this.broadcastManager = con.ˊ(paramContext);
  if (paramBoolean)
    startTracking();
}
项目:QuizUpWinner    文件:Facebook.java   
private void authorize(Activity paramActivity, String[] paramArrayOfString, int paramInt, SessionLoginBehavior paramSessionLoginBehavior, final DialogListener paramDialogListener)
{
  checkUserSession("authorize");
  this.pendingOpeningSession = new Session.Builder(paramActivity).setApplicationId(this.mAppId).setTokenCachingStrategy(getTokenCache()).build();
  this.pendingAuthorizationActivity = paramActivity;
  String[] arrayOfString;
  if (paramArrayOfString != null)
    arrayOfString = paramArrayOfString;
  else
    arrayOfString = new String[0];
  this.pendingAuthorizationPermissions = arrayOfString;
  Session.StatusCallback local1 = new Session.StatusCallback()
  {
    public void call(Session paramAnonymousSession, SessionState paramAnonymousSessionState, Exception paramAnonymousException)
    {
      Facebook.this.onSessionCallback(paramAnonymousSession, paramAnonymousSessionState, paramAnonymousException, paramDialogListener);
    }
  };
  Session.OpenRequest localOpenRequest = new Session.OpenRequest(paramActivity).setCallback(local1).setLoginBehavior(paramSessionLoginBehavior).setRequestCode(paramInt).setPermissions(Arrays.asList(this.pendingAuthorizationPermissions));
  Session localSession = this.pendingOpeningSession;
  boolean bool;
  if (this.pendingAuthorizationPermissions.length > 0)
    bool = true;
  else
    bool = false;
  openSession(localSession, localOpenRequest, bool);
}
项目:QuizUpWinner    文件:PickerFragment.java   
public void onActivityCreated(Bundle paramBundle)
{
  super.onActivityCreated(paramBundle);
  this.sessionTracker = new SessionTracker(getActivity(), new Session.StatusCallback()
  {
    public void call(Session paramAnonymousSession, SessionState paramAnonymousSessionState, Exception paramAnonymousException)
    {
      if (!paramAnonymousSession.isOpened())
        PickerFragment.this.clearResults();
    }
  });
  setSettingsFromBundle(paramBundle);
  this.loadingStrategy = createLoadingStrategy();
  this.loadingStrategy.attach(this.adapter);
  this.selectionStrategy = createSelectionStrategy();
  this.selectionStrategy.readSelectionFromBundle(paramBundle, "com.facebook.android.PickerFragment.Selection");
  if (this.showTitleBar)
    inflateTitleBar((ViewGroup)getView());
  if ((this.activityCircle != null) && (paramBundle != null))
  {
    if (paramBundle.getBoolean("com.facebook.android.PickerFragment.ActivityCircleShown", false))
    {
      displayActivityCircle();
      return;
    }
    hideActivityCircle();
  }
}
项目:DualRunner    文件:FBLogin.java   
private static Session.StatusCallback getAfterReadPermissionLoginCallback(final UnityMessage unityMessage, final List<String> publishPermissions, final Activity activity) {
    return new Session.StatusCallback() {
        // callback when session changes state
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.getState().equals(SessionState.OPENING)){
                return;
            }
            session.removeCallback(this);

            if (!session.isOpened() && state != SessionState.CLOSED_LOGIN_FAILED) {
                unityMessage.sendError("Unknown error while opening session. Check logcat for details.");
                activity.finish();
                return;
            }

            // if someone cancels on the read permissions and we don't even have the most basic access_token
            // for basic info, we shouldn't be asking for publish permissions.  It doesn't make sense
            // and it simply won't work anyways.
            if (session.getAccessToken() == null || session.getAccessToken().equals("")) {
                unityMessage.putCancelled();
                unityMessage.send();
                activity.finish();
                return;
            }

            //ask for publish permissions, if necessary.
            if(session.getPermissions().containsAll(publishPermissions)) {
                finalizeLogin(session, state, exception, unityMessage, activity);
            } else {
                Session.StatusCallback finalCallback = getFinalCallback(unityMessage, activity);
                sessionOpenRequest(session, finalCallback, activity, publishPermissions, true);
            }
        }
    };
}
项目:DualRunner    文件:FBLogin.java   
private static Session.StatusCallback getFinalCallback(final UnityMessage unityMessage, final Activity activityToClose) {
    return new Session.StatusCallback() {
        // callback when session changes state
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.getState().equals(SessionState.OPENING)){
                return;
            }
            session.removeCallback(this);

            finalizeLogin(session, state, exception, unityMessage, activityToClose);
        }
    };
}
项目:DualRunner    文件:FBLogin.java   
private static OpenRequest getOpenRequest(StatusCallback callback, List<String> permissions, Activity activity) {
    OpenRequest req = new OpenRequest(activity);
    req.setCallback(callback);
    req.setPermissions(permissions);
    req.setDefaultAudience(SessionDefaultAudience.FRIENDS);

    return req;
}
项目:DualRunner    文件:FBLogin.java   
private static Session.NewPermissionsRequest getNewPermissionsRequest(Session session, StatusCallback callback, List<String> permissions, Activity activity) {
    Session.NewPermissionsRequest req = new Session.NewPermissionsRequest(activity, permissions);
    req.setCallback(callback);
    // This should really be "req.setCallback(callback);"
    // Unfortunately the current underlying SDK won't add the callback when you do it that way
    // TODO: when upgrading to the latest see if this can be "req.setCallback(callback);"
    // if it still doesn't have it, file a bug!
    session.addCallback(callback);
    req.setDefaultAudience(SessionDefaultAudience.FRIENDS);
    return req;
}
项目:gendreapp    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new PlaceholderFragment()).commit();
    }
    // dump hash for FB integration
    if (BuildConfig.DEBUG) {
        dumpHash();
    }

    IntentFilter filter = new IntentFilter(ResponseReceiver.ACTION_STATUS);
    filter.addCategory(Intent.CATEGORY_DEFAULT);
    receiver = new ResponseReceiver(this);
    registerReceiver(receiver, filter);

    // FB stuff
    StatusCallback callback = new StatusCallback() {

        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            if (exception != null) {
                Log.e("Activity", //$NON-NLS-1$
                        String.format("Error: %s", exception.toString())); //$NON-NLS-1$
                exception.printStackTrace();
            }
        }

    };
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
}
项目:android_socialmedia    文件:MainActivity.java   
private Session openActiveSession(Activity activity, boolean allowLoginUI, StatusCallback callback,
        List<String> permissions) {
    OpenRequest openRequest = new OpenRequest(activity).setPermissions(permissions).setCallback(callback);
    Session session = new Session.Builder(activity).build();
    if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {
        Session.setActiveSession(session);
        session.openForPublish(openRequest);
        return session;
    }
    return null;
}
项目:Free-D-Unity    文件:FB.java   
private static OpenRequest getOpenRequest(StatusCallback callback, List<String> permissions) {
    OpenRequest req = new OpenRequest(getActivity());
    req.setCallback(callback);
    req.setPermissions(permissions);
    req.setDefaultAudience(SessionDefaultAudience.FRIENDS);

    return req;
}
项目:Free-D-Unity    文件:FB.java   
private static Session.NewPermissionsRequest getNewPermissionsRequest(Session session, StatusCallback callback, List<String> permissions) {
    Session.NewPermissionsRequest req = new Session.NewPermissionsRequest(getActivity(), permissions);
    req.setCallback(callback);
    // This should really be "req.setCallback(callback);"
    // Unfortunately the current underlying SDK won't add the callback when you do it that way
    // TODO: when upgrading to the latest see if this can be "req.setCallback(callback);"
    // if it still doesn't have it, file a bug!
    session.addCallback(callback);
    req.setDefaultAudience(SessionDefaultAudience.FRIENDS);
    return req;
}
项目:InsanityRadio-Android    文件:FacebookFacadeV3.java   
protected Session.StatusCallback createLoginCallback(final AuthProviderListener listener) {

        return new Session.StatusCallback() {

            // callback when session changes state
            @Override
            public void call(final Session session, SessionState state, Exception exception) {

                if(exception != null && exception instanceof FacebookOperationCanceledException) {
                    if(logger != null) {
                        logger.error("Facebook operation failed", exception);
                    }
                    handleCancel(listener);
                    return;
                }

                switch(state) {

                    case OPENED:
                        if (isSessionOpen(session)) {
                            // make request to the /me API
                            getUser(session, listener);
                        }

                        break;

                    case CLOSED:
                        if(exception != null) {
                            handleError(exception, listener);
                        }
                        break;

                    case CLOSED_LOGIN_FAILED:
                        if(exception != null) {
                            handleAuthFail(exception, listener);
                        }
                        break;
                }
            }
        };
    }
项目:InsanityRadio-Android    文件:FacebookFacadeV3.java   
@Override
public void getCurrentPermissions(Activity context, String token, final OnPermissionResult callback) {
    Session activeSession = getActiveSession(context);

    if(activeSession != null) {
        if(activeSession.getAccessToken().equals(token)) {
            callback.onSuccess((String[])activeSession.getPermissions().toArray(new String[activeSession.getPermissions().size()]));
        }
        else {
            AccessToken accessToken = AccessToken.createFromExistingAccessToken(
                    token,
                    null, null, null, null);

            // We must close the current session
            if(activeSession.isOpened()) {
                activeSession.closeAndClearTokenInformation();
                activeSession = new Session.Builder(context).setApplicationId(config.getProperty(SocializeConfig.FACEBOOK_APP_ID)).build();
            }

            activeSession.open(accessToken, new StatusCallback() {
                @Override
                public void call(Session session, SessionState state, Exception exception) {
                    if(exception != null) {
                        if(callback != null) {
                            callback.onError(SocializeException.wrap(exception));
                        }
                        else if(logger != null) {
                            logger.error("Error accessing permissions for alternate token", exception);
                        }
                        else {
                            Log.e("Socialize", "Error accessing permissions for alternate token", exception);
                        }
                    }
                    else {
                        Session.setActiveSession(session);
                        if(callback != null) {
                            callback.onSuccess((String[])session.getPermissions().toArray(new String[session.getPermissions().size()]));
                        }
                    }
                }
            });
        }           
    }
    else {
        handleNotSignedIn(context, callback);
    }
}
项目:InsanityRadio-Android    文件:FacebookFacadeV3.java   
protected Session.StatusCallback createLoginCallback(final AuthProviderListener listener) {

        return new Session.StatusCallback() {

            // callback when session changes state
            @Override
            public void call(final Session session, SessionState state, Exception exception) {

                if(exception != null && exception instanceof FacebookOperationCanceledException) {
                    if(logger != null) {
                        logger.error("Facebook operation failed", exception);
                    }
                    handleCancel(listener);
                    return;
                }

                switch(state) {

                    case OPENED:
                        if (isSessionOpen(session)) {
                            // make request to the /me API
                            getUser(session, listener);
                        }

                        break;

                    case CLOSED:
                        if(exception != null) {
                            handleError(exception, listener);
                        }
                        break;

                    case CLOSED_LOGIN_FAILED:
                        if(exception != null) {
                            handleAuthFail(exception, listener);
                        }
                        break;
                }
            }
        };
    }
项目:InsanityRadio-Android    文件:FacebookFacadeV3.java   
@Override
public void getCurrentPermissions(Activity context, String token, final OnPermissionResult callback) {
    Session activeSession = getActiveSession(context);

    if(activeSession != null) {
        if(activeSession.getAccessToken().equals(token)) {
            callback.onSuccess((String[])activeSession.getPermissions().toArray(new String[activeSession.getPermissions().size()]));
        }
        else {
            AccessToken accessToken = AccessToken.createFromExistingAccessToken(
                    token,
                    null, null, null, null);

            // We must close the current session
            if(activeSession.isOpened()) {
                activeSession.closeAndClearTokenInformation();
                activeSession = new Session.Builder(context).setApplicationId(config.getProperty(SocializeConfig.FACEBOOK_APP_ID)).build();
            }

            activeSession.open(accessToken, new StatusCallback() {
                @Override
                public void call(Session session, SessionState state, Exception exception) {
                    if(exception != null) {
                        if(callback != null) {
                            callback.onError(SocializeException.wrap(exception));
                        }
                        else if(logger != null) {
                            logger.error("Error accessing permissions for alternate token", exception);
                        }
                        else {
                            Log.e("Socialize", "Error accessing permissions for alternate token", exception);
                        }
                    }
                    else {
                        Session.setActiveSession(session);
                        if(callback != null) {
                            callback.onSuccess((String[])session.getPermissions().toArray(new String[session.getPermissions().size()]));
                        }
                    }
                }
            });
        }           
    }
    else {
        handleNotSignedIn(context, callback);
    }
}
项目:QuizUpWinner    文件:SessionTracker.java   
public SessionTracker(Context paramContext, Session.StatusCallback paramStatusCallback)
{
  this(paramContext, paramStatusCallback, null);
}
项目:QuizUpWinner    文件:SessionTracker.java   
SessionTracker(Context paramContext, Session.StatusCallback paramStatusCallback, Session paramSession)
{
  this(paramContext, paramStatusCallback, paramSession, true);
}
项目:QuizUpWinner    文件:SessionTracker.java   
public CallbackWrapper(Session.StatusCallback arg2)
{
  Object localObject;
  this.wrapped = localObject;
}
项目:QuizUpWinner    文件:LoginButton.java   
public Session.StatusCallback getSessionStatusCallback()
{
  return this.properties.getSessionStatusCallback();
}
项目:QuizUpWinner    文件:LoginButton.java   
public void setSessionStatusCallback(Session.StatusCallback paramStatusCallback)
{
  this.properties.setSessionStatusCallback(paramStatusCallback);
}
项目:QuizUpWinner    文件:LoginButton.java   
public Session.StatusCallback getSessionStatusCallback()
{
  return this.sessionStatusCallback;
}
项目:QuizUpWinner    文件:LoginButton.java   
public void setSessionStatusCallback(Session.StatusCallback paramStatusCallback)
{
  this.sessionStatusCallback = paramStatusCallback;
}
项目:QuizUpWinner    文件:UserSettingsFragment.java   
public Session.StatusCallback getSessionStatusCallback()
{
  return this.sessionStatusCallback;
}
项目:QuizUpWinner    文件:UserSettingsFragment.java   
public void setSessionStatusCallback(Session.StatusCallback paramStatusCallback)
{
  this.sessionStatusCallback = paramStatusCallback;
}
项目:DualRunner    文件:FBLogin.java   
public static void login(String params, final Activity activity) {
    Session session = Session.getActiveSession();
    if (session == null) {
        Log.w(FB.TAG, "Session not found. Call init() before calling login()");
        return;
    }
    // if the old session is closed (or login was cancelled), create new one
    if (session.isClosed()) {
        session = new Builder(FB.getUnityActivity()).setApplicationId(session.getApplicationId()).build();
        Session.setActiveSession(session);
    }
    final UnityMessage unityMessage = new UnityMessage("OnLoginComplete");

    unityMessage.put("key_hash", FB.getKeyHash());

    // parse and separate the permissions into read and publish permissions
    List<String> permissions = new ArrayList<String>();
    UnityParams unity_params = UnityParams.parse(params, "couldn't parse login params: " + params);
    if (unity_params.hasString("scope")) {
        permissions = new ArrayList<String>(Arrays.asList(unity_params.getString("scope").split(",")));
    }
    List<String> publishPermissions = new ArrayList<String>();
    List<String> readPermissions = new ArrayList<String>();
    if(permissions.size() > 0) {
        for(String s:permissions) {
            if(s.length() == 0) {
                continue;
            }
            if(Session.isPublishPermission(s)) {
                publishPermissions.add(s);
            } else {
                readPermissions.add((s));
            }
        }
    }
    boolean hasPublishPermissions = !publishPermissions.isEmpty();

    // check to see if the readPermissions have been TOSed already
    // we don't need to show the readPermissions dialog if they have all been TOSed even though it's a mix
    // of permissions
    boolean showMixedPermissionsFlow = hasPublishPermissions && !session.getPermissions().containsAll(readPermissions);

    // if we're logging in and showing a mix of publish and read permission, we need to split up the dialogs
    // first just show the read permissions, after they are accepted show publish permissions
    if (showMixedPermissionsFlow) {
        Session.StatusCallback afterReadPermissionCallback = getAfterReadPermissionLoginCallback(unityMessage, publishPermissions, activity);
        sessionOpenRequest(session, afterReadPermissionCallback, activity, readPermissions, false);
    } else {
        Session.StatusCallback finalCallback = getFinalCallback(unityMessage, activity);
        sessionOpenRequest(session, finalCallback, activity, permissions, hasPublishPermissions);
    }
}
项目:CodePix-Android    文件:SettingsFragment.java   
private void login() {



     try {
        if (Session.getActiveSession() == null
                    || Session.getActiveSession().isClosed()) {
                Session.openActiveSession(getActivity(), true, new StatusCallback() {

                    @SuppressWarnings("deprecation")
                    @Override
                    public void call(Session session, SessionState state,
                            Exception exception) {
                        System.out.println("State= " + state);

                        if (session.isOpened()) {
                            System.out.println("Token=" + session.getAccessToken());

                            mPrefs.edit().putString("fbToken", session.getAccessToken()).commit();
                            Request.executeMeRequestAsync(session,
                                    new GraphUserCallback() {
                                        @Override
                                        public void onCompleted(GraphUser user,
                                                Response response) {
                                            if (user != null) {
                                                System.out.println("User=" + user);

                                            }
                                            pd.dismiss();
                                        }
                                    });
                        }
                        if (exception != null) {
                            System.out.println("Some thing bad happened!");
                            exception.printStackTrace();


                            pd.dismiss();

                            GlobalMethods.showMessage(getActivity(), "Facebook connect failed.");
                        }
                    }
                });
            }
    } catch (Exception e) {

        pd.dismiss();
        e.printStackTrace();
        GlobalMethods.showMessage(getActivity(), getString(R.string.internet_error));
    }
}
项目:CodePix-Android    文件:ImageDistortedUploadActivity.java   
private void login() {
     try {
    if (Session.getActiveSession() == null
                || Session.getActiveSession().isClosed()) {
            Session.openActiveSession(ImageDistortedUploadActivity.this, true, new StatusCallback() {

                @SuppressWarnings("deprecation")
                @Override
                public void call(Session session, SessionState state,
                        Exception exception) {
                    System.out.println("State= " + state);

                    if (session.isOpened()) {
                        System.out.println("Token=" + session.getAccessToken());

                        mPrefs.edit().putString("fbToken", session.getAccessToken()).commit();
                        Request.executeMeRequestAsync(session,
                                new GraphUserCallback() {
                                    @Override
                                    public void onCompleted(GraphUser user,
                                            Response response) {
                                        if (user != null) {
                                            System.out.println("User=" + user);

                                        }
                                        pd.dismiss();
                                    }
                                });
                    }
                    if (exception != null) {
                        System.out.println("Some thing bad happened!");
                        exception.printStackTrace();

                        pd.dismiss();

                        GlobalMethods.showMessage(getApplicationContext(), "Facebook Share failed.");
                    }
                }
            });
        }
} catch (Exception e) {
    // TODO Auto-generated catch block

    pd.dismiss();
    e.printStackTrace();
    GlobalMethods.showMessage(getApplicationContext(), getString(R.string.internet_error));
}
  }
项目:CodePix-Android    文件:ImageDistortedUploadActivity.java   
private void publishStory() {

    try {
    Session.openActiveSession(this, true, new Session.StatusCallback() {

      // callback when session changes state
         @Override
          public void call(Session session, SessionState state, Exception exception) {
              if (session.isOpened()) {



                    if (session != null){


                    if(session.isOpened() && state == SessionState.OPENED && !session.getPermissions().contains("publish_stream")){
                          final String[] PERMISSION_ARRAY_PUBLISH = {"publish_stream"};
                          final List<String> permissionList = Arrays.asList(PERMISSION_ARRAY_PUBLISH);
                          session.requestNewPublishPermissions(new NewPermissionsRequest(ImageDistortedUploadActivity.this,permissionList ));
                          return;
                      }

                   // Bundle postParams = new Bundle();
                   // postParams.putString("name", "Facebook SDK for Android");
                   // postParams.putString("caption", "Build great social apps and get more installs.");
                   // postParams.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
                   // postParams.putString("link", "https://developers.facebook.com/android");
                   // postParams.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
                    byte[] data = null;

                    Bitmap bi = BitmapFactory.decodeFile(new File(filePathDistorted).getAbsolutePath());
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                    data = baos.toByteArray();




                    Request.Callback callback= new Request.Callback() {
                        @Override
                        public void onCompleted(Response response) {
                            System.out.println("response"+response);
                        }
                    };

                    Request request = Request.newUploadPhotoRequest(session,bi, callback);
                 Bundle params = request.getParameters();
                  params.putString("message", editTextCaption.getText().toString()+": To view image, click here to download CodePix");
                   // params.putString("method", "photos.upload");
                    //params.putByteArray("picture", data);
                    //params.putString("link", "https://developers.facebook.com/android");
                request.setParameters(params);
                    RequestAsyncTask task = new RequestAsyncTask(request);
                    task.execute();
                }
                    //Request.executeBatchAsync(request); 
              }    
          }

    });
} catch (Exception e) {
    // TODO Auto-generated catch block
    pd.dismiss();
    e.printStackTrace();
    GlobalMethods.showMessage(getApplicationContext(), getString(R.string.internet_error));
}




    }
项目:android_socialmedia    文件:MainActivity.java   
private void loginToFacebook() {
    openActiveSession(this, true, new StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                Session.setActiveSession(session);
                Request.newMeRequest(session, new GraphUserCallback() {

                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            Log.d("facebook name", user.getName() + " " + user.asMap().get("email"));
                            String userimage = "http://graph.facebook.com/" + user.getId() + "/picture?style=small";

                            Editor editor = sharedPreferences.edit();
                            editor.putString(Config.ACCOUNT, "Facebook");
                            editor.putString(Config.NAME, "Name: " + user.getName());
                            editor.putString(Config.IMAGE, userimage);
                            String location = null;
                            try {
                                location = user.getLocation().getCity();
                                if (location == null || location.equals(""))
                                    location = "Not found";
                            } catch (Exception e) {
                                e.printStackTrace();
                                location = "Not found";
                            }

                            String data = "UserName: " + user.getUsername() + "\n" + "Location: " + location + "\n";
                            editor.putString(Config.DATA, data);
                            editor.commit();

                            /*
                             * HashMap<String, String> map = new
                             * HashMap<String, String>(); map.put("account",
                             * "Google+"); map.put("name",
                             * "Name:\n"+user.getFirstName
                             * ()+" "+user.getLastName()); map.put("image",
                             * userimage); String data =
                             * "UserName: "+user.getUsername()+"\n"+
                             * "Location: "+user.getLocation()+"\n";
                             * map.put("userData", data);
                             */
                            // in.putExtra("data", map);
                            startActivity(new Intent(MainActivity.this, ResultActivity.class));
                            overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
                            finish();
                        }
                    }
                }).executeAsync();
            }
        }
    }, Arrays.asList("email", "publish_actions"));
}