Exemplo n.º 1
0
  public void auth(final Activity activity, String[] scope, OnAuthListener listener) {
    authListener = listener;
    currentAction = ACTION_AUTH;

    simpleFacebook = SimpleFacebook.getInstance(activity);

    simpleFacebook.login(
        new OnLoginListener() {
          @Override
          public void onLogin(
              final String accessToken,
              List<Permission> acceptedPermissions,
              List<Permission> declinedPermissions) {
            // (accessToken, simpleFacebook.getAccessToken().getUserId());
            switch (currentAction) {
              case ACTION_AUTH:
                if (authListener != null) {
                  authListener.onSuccess(
                      VKSdk.getAccessToken().accessToken, VKSdk.getAccessToken().userId);
                }
                break;
              case ACTION_POST:
                post(activity, SSNetwork.getBitmap(), SSNetwork.getText(), getListener());
                break;
            }

            currentAction = ACTION_NONE;
          }

          @Override
          public void onCancel() {
            // user canceled the dialog
            Log.i(TAG, "cancel");
          }

          @Override
          public void onFail(String reason) {
            // failed to login
            switch (currentAction) {
              case ACTION_AUTH:
                if (authListener != null) authListener.onError(reason);
                break;
            }

            Log.e(TAG, "error: " + reason);
          }

          @Override
          public void onException(Throwable throwable) {
            // exception from facebook
            switch (currentAction) {
              case ACTION_AUTH:
                if (authListener != null) authListener.onError(throwable.toString());
                break;
            }

            Log.e(TAG, "error: " + throwable.toString());
          }
        });
  }
 @Override
 public void onResume() {
   super.onResume();
   mSimpleFacebook = SimpleFacebook.getInstance(getActivity());
   setUIState();
 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   SimpleFacebook.getInstance(this).onActivityResult(this, requestCode, resultCode, data);
 }