title: retrieving direct messages twitter api
body: <p>I want to retrieve direct messages from twitter using TwitterAPIExchange.php. The settings in my application are: write/read and direct messages. What I am missing? Merry Christmas</p>
  
  <p>Updated Code</p>
  
  <pre><code>   $settings = array(
    'oauth_access_token' =&gt; $accessToken,
    'oauth_access_token_secret' =&gt; $accessTokenSecret,
    'consumer_key' =&gt; $consumerKey,
    'consumer_secret' =&gt; $consumerKeySecret
  );
  $i = 0;
  $cursor = -1;
  
  do {
    $url = 'https://api.twitter.com/1.1/direct_messages.json';
    $getfield = '?cursor='.$cursor.'since_id=240136858829479935&amp;count=1';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $response = $twitter-&gt;setGetfield($getfield)
                        -&gt;buildOauth($url, $requestMethod)
                        -&gt;performRequest();
  
    $response = json_decode($response, true);
  
    if (!empty($response["next_cursor_str"])) {
      $next_cursor = $response["next_cursor_str"];
    } else {
      $next_cursor = 0;
    }
  
    $errors = $response["errors"];
  
    if (!empty($errors)) {
      foreach($errors as $error){
        $code = $error['code'];
        $msg = $error['message'];
        echo "&lt;br&gt;&lt;br&gt;Error " . $code . ": " . $msg;
      }
      $cursor = 0;
    } else {
        $users = $response['tweets'];
        foreach($users as $user) {
            echo 'tweet:'  .  $user['text'] . '&lt;/br&gt;';
        }
    }
    if ($next_cursor != null) {
      $cursor = $next_cursor;
    }
  } while ( $cursor != 0);
  </code></pre>
  
  <p>Solved.
  Please read this code that could help you.</p>
  
  <pre><code> ini_set('display_errors', 1);
   require_once('TwitterAPIExchange.php'); 
  $settings = array( 
      'oauth_access_token' =&gt; "xxx",
      'oauth_access_token_secret' =&gt; "xxx",
      'consumer_key' =&gt; "xxx",
      'consumer_secret' =&gt; "xxx");
    $url = 'https://api.twitter.com/1.1/direct_messages.json';
    $getfield = '?since_id=240136858829479935&amp;count=1';
    $requestMethod = 'GET';
  $twitter = new TwitterAPIExchange($settings);
  $string = json_decode($twitter-&gt;setGetfield($getfield)
               -&gt;buildOauth($url, $requestMethod)
               -&gt;performRequest(),$assoc = TRUE);
  
  echo "&lt;h3&gt;Mensajer directos&lt;/h3&gt;";          
  foreach($string as $items)
   {
              $url = 'https://api.twitter.com/1.1/direct_messages/show.json?';
              $requestMethod = 'GET';
              $getfields = array('id' =&gt; $items['id']);
              $twitter = new TwitterAPIExchange($settings);           
              $do = $twitter-&gt;setGetfield($getfield)
                            -&gt;buildOauth($url, $requestMethod)                         
                            -&gt;performRequest();
              echo "&lt;strong&gt;Teet:&lt;/strong&gt; ".$items['text']."&lt;br /&gt;";
              var_dump(json_encode($items, true));
          }
  </code></pre>