title: Get GIFs/Video from my favorite Tweet and show it in a web page , via API
body: <p><strong>My goal</strong> : Show in a web page all the GIFs/Video present in my favorite tweet</p>
  
  <p>To do this i'm using <a href="https://dev.twitter.com/rest/public" rel="nofollow">Twitter REST APIs</a> and <a href="https://github.com/J7mbo/twitter-api-php/blob/master/TwitterAPIExchange.php" rel="nofollow">this php class (TwitterAPIExchange.php)</a></p>
  
  <p>Code for get my favorite tweet , this prints out the text of each of my favorite tweet</p>
  
  <pre><code>require_once('TwitterAPIExchange.php');
  
  
  $settings = array(
      'oauth_access_token' =&gt; "XXXXXXX",
      'oauth_access_token_secret' =&gt; "XXXXXXX",
      'consumer_key' =&gt; "XXXXXXX",
      'consumer_secret' =&gt; "XXXXXXX"
  );
  
  $url = 'https://api.twitter.com/1.1/favorites/list.json';
  $getfield = '?count=200&amp;screen_name=XXXXX&amp;include_entities=false';
  
  $requestMethod = 'GET';
  $twitter = new TwitterAPIExchange($settings);
  
  $result = $twitter-&gt;setGetfield($getfield)
               -&gt;buildOauth($url, $requestMethod)
               -&gt;performRequest();  
  
  $result_array = json_decode($result , true);
  
  for($i = 0 ; $i &lt; count($result_array) ; $i++){
      echo $result_array[$i]["text"]."&lt;br&gt;&lt;br&gt;";
  }
  </code></pre>
  
  <p>Now I should extrapolate the http address of each GIFs/Video (and for that I have no problems) and view it, the problem is that the address of the GIFs/Video doesn't point directly to the GIFs/Video</p>
  
  <h2>UPDATE 1</h2>
  
  <p>Now i tried this :</p>
  
  <pre><code>$url = 'https://api.twitter.com/1.1/favorites/list.json';
  $getfield = '?count=200&amp;screen_name=XXXXX&amp;include_entities=true';
  .....
  .....
  $app_video = array();
  for($i = 0 ; $i &lt; count($result_array) ; $i++){
      array_push($app_video, $result_array[$i]["entities"]["urls"][0]["expanded_url"]);
  }
  </code></pre>
  
  <p>to get an array with the links of all videos</p>
  
  <h2>UPDATE 2</h2>
  
  <p>Now , after extrapolated the link of all videos (update 1), with <strong>file_get_contents</strong> and using <strong>DomDocument</strong> , i have extrapolate the</p>
  
  <pre><code>&lt;video&gt; &lt;source ...&gt; &lt;/ video&gt;
  </code></pre>
  
  <p>from the page.</p>
  
  <h2>UPDATE 3</h2>
  
  <p>This is my final solution</p>
  
  <pre><code>require_once('TwitterAPIExchange.php');
  
  
  $settings = array(
      'oauth_access_token' =&gt; "XXXXXX",
      'oauth_access_token_secret' =&gt; "XXXXXX",
      'consumer_key' =&gt; "XXXXXX",
      'consumer_secret' =&gt; "XXXXXX"
  );
  
  $url = 'https://api.twitter.com/1.1/favorites/list.json';
  $getfield = '?count=200&amp;screen_name=XXXXX&amp;include_entities=true';
  
  $requestMethod = 'GET';
  $twitter = new TwitterAPIExchange($settings);
  
  $result = $twitter-&gt;setGetfield($getfield)
               -&gt;buildOauth($url, $requestMethod)
               -&gt;performRequest();  
  
  $result_array = json_decode($result , true);
  
  
  for($i = 0 ; $i &lt; count($result_array) ; $i++){
  
     $link = $result_array[$i]["entities"]["urls"][0]["expanded_url"];
  
     if(strpos($link,"twitter.com") !== false){
  
          $pageContent = file_get_contents($link , true);
  
          @$dom = new DOMDocument;
          @$dom-&gt;loadHTML($pageContent);
  
          $p = $dom-&gt;getElementsByTagName('video')-&gt;item(0);
          $source = $p-&gt;getElementsByTagName('source');
  
          $src = $source-&gt;item(0)-&gt;getAttribute("video-src");
  
  
          echo '&lt;video name="media" loop="true" autoplay="true" src="'.$src.'"&gt;';
              echo '&lt;source video-src="'.$src.'" type="video/mp4" class="source-mp4" src="'.$src.'"&gt;';
          echo '&lt;/video&gt;';
  
     }
  
  }
  
  
  function get_inner_html( $node ) { 
      $innerHTML= ''; 
      $children = $node-&gt;childNodes; 
      foreach ($children as $child) { 
          $innerHTML .= $child-&gt;ownerDocument-&gt;saveXML( $child ); 
      } 
      return $innerHTML; 
  } 
  </code></pre>
  
  <hr>
  
  <h2><strong>This solution works, but i think i can do better. In this way , i have to load each page of each tweet , and of course this method is very slow.</strong></h2>
  
  <hr>