title: android - facebook premission ,Session: an attempt was made to request new permissions for a session that has a pending request
body: <p>when I use <a href="https://github.com/facebook/facebook-ios-sdk/tree/master/samples/HelloFacebookSample" rel="nofollow noreferrer">HelloFacebookSample</a> the code works fine and I was able to post on the user wall.</p>
  
  <p>but when I try to post video and <a href="https://stackoverflow.com/questions/17202305/posting-an-embedded-youtube-link-using-the-facebook-sdk">embeded it on the wall</a>  , to do so I used <a href="http://developers.facebook.com/docs/howtos/androidsdk/3.0/publish-to-feed/" rel="nofollow noreferrer">publish to feed tutorial</a> </p>
  
  <p>when i convert my code i replace  <code>postStatusUpdate()</code> methood with <code>publishStory()</code></p>
  
  <pre><code>public void postStatusUpdate() {
          if (user != null &amp;&amp; hasPublishPermission()) {
              final String message ;
  
  
  
                  message = ( user.getFirstName()+" "+ getString( R.string.status_update_link)+ " " +video_id + " " + getString(R.string.google_play_link));
  
  
              Request request = Request
                      .newStatusUpdateRequest(Session.getActiveSession(), message, new Request.Callback() {
                          @Override
                          public void onCompleted(Response response) {
                              showPublishResult(message, response.getGraphObject(), response.getError());
                          }
                      });
              request.executeAsync();
          } else {
              pendingAction = PendingAction.POST_STATUS_UPDATE;
          }
      }
  </code></pre>
  
  <p>replace with this : </p>
  
  <pre><code>private void publishStory() {
          Session session = Session.getActiveSession();
  
          if (session != null){
  
              // Check for publish permissions    
              List&lt;String&gt; permissions = session.getPermissions();
              if (!isSubsetOf(PERMISSIONS, permissions)) {
  
                  Session.NewPermissionsRequest newPermissionsRequest = new Session
                          .NewPermissionsRequest(this, PERMISSIONS);
              session.requestNewPublishPermissions(newPermissionsRequest);
                  return;
              }
  
              Bundle postParams = new Bundle();
  
  
  
                  postParams.putString("message", getString( R.string.google_play_link));
                  postParams.putString("link", "http://www.youtube.com/watch?v="+ video_id);
                  postParams.putString("source", "http://www.youtube.com/v/" + video_id);
                  postParams.putString("picture","http://img.youtube.com/vi/" +video_id + "/0.jpg");
  
  
  
  
  
      Request.Callback callback= new Request.Callback() {
          public void onCompleted(Response response) {
              JSONObject graphResponse = response
                                         .getGraphObject()
                                         .getInnerJSONObject();
              String postId = null;
              try {
                  postId = graphResponse.getString("id");
              } catch (JSONException e) {
                  Log.i(TAG,
                      "JSON error "+ e.getMessage());
              }
              FacebookRequestError error = response.getError();
              if (error != null) {
  
  
                  Toast.makeText(MyApp.intense,
                       error.getErrorMessage(),
                       Toast.LENGTH_LONG).show();
  
                  } else {
  
                  /** 
                      Toast.makeText(MyApp.intense, 
                          // postId
                              "Sent"
                           ,
                           Toast.LENGTH_LONG).show();
                   */        
              }
          }
      };
  
      Request request = new Request(session, "me/feed", postParams, 
                            HttpMethod.POST, callback);
  
      RequestAsyncTask task = new RequestAsyncTask(request);
      task.execute();
  }
  
  }
  </code></pre>
  
  <p>so when i try to post, the app is cresh and I recieve " Session: an attempt was made to request new permissions for a session that has a pending request"</p>
  
  <p>I dont find when the first permission...</p>
  
  <p>in other Q that posted in this form the developer recieve the same error MSG like I receive but it look like this error appear when the <a href="https://stackoverflow.com/questions/16932885/session-an-attempt-was-made-to-request-new-permissions-for-a-session-that-has-a">session is not  OPENED</a> and the user call it, I belive that not the problem in this case.</p>
  
  <p>I attached more code from this FragmentActivity because I believe it necessary. </p>
  
  <pre><code> private void onSessionStateChange(Session session, SessionState state, Exception exception) {
          if (pendingAction != PendingAction.NONE &amp;&amp;
                  (exception instanceof FacebookOperationCanceledException ||
                  exception instanceof FacebookAuthorizationException)) {
                  new AlertDialog.Builder(HelloFacebookSampleActivity.this)
                      .setTitle(R.string.cancelled)
                      .setMessage(R.string.permission_not_granted)
                      .setPositiveButton(R.string.ok, null)
                      .show();
                  postStatusUpdateButton.setEnabled(false);
              pendingAction = PendingAction.NONE;
          } else if (state == SessionState.OPENED_TOKEN_UPDATED) {
              handlePendingAction();
          }
          updateUI();
      }
  
  
  
  
  private enum PendingAction {
          NONE,
  
          POST_STATUS_UPDATE
      }
      private UiLifecycleHelper uiHelper;
  
      private Session.StatusCallback callback = new Session.StatusCallback() {
          @Override
          public void call(Session session, SessionState state, Exception exception) {
              onSessionStateChange(session, state, exception);
          }
      };
  </code></pre>