We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40344
    • 9 Posts
    I'm a new MODx user trying to help a non profit startup.
    Immediate task is to get twitter feed working. I found the below code an wondered if you need to point to a specific twitter user to get results?

    <div class="module">
                <ul>
           [[!getFeed? &url=`https://twitter.com/statuses/user_timeline/[[++twitter]].rss` &limit=`4`&tpl=`twitter-feed-tpl`]]
                </ul>
     </div><!--eof module -->
    


    Thanks!

    WBR
      • 3749
      • 24,544 Posts
      I used this code successfully.

      You need the files twitteroauth.php and OAuth.php -- they should be in the same directory -- adjust the path to twitteroauth.php -- change BobRay to your user's screen name.

      <?php
      define('CONSUMER_KEY', '');
      define('CONSUMER_SECRET', '');
      define('OAUTH_TOKEN', '');
      define('OAUTH_SECRET', '');
      
      require_once('twitteroauth.php');
      
      
      $tweet = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
      
      /* This will send a tweet, but you need to set the tokens above */
      
      //$text = 'Tweeted from PHP - just testing some code';
      //$response = $tweet->post('statuses/update', array('status' => $text));
      
      $response = $tweet->get('statuses/user_timeline', array('screen_name' => 'BobRay'));
      
      if (!$response) {
          echo "<_h3>Unknown error using the Twitter API</h3_>";
      } elseif (isset($response->error) && $response->error) {
          echo "<_h3>Twitter said, there was an error</h3_>";
          echo "<_code>$response->error</code_>";
          echo "<_p>Full response:</p_>";
          echo "<_pre>" . var_dump($response) . "</pre_>";
      } else {
      
          //echo "<_pre>" . var_dump($response) . "</pre_>";
      
          foreach ($response as $x) {
              echo ($x->text). "\n";
          }
      }



      Your code might work if you added the screen name to the URL:

      &screen_name=ActualScreenName

      There's documentation here: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 40344
        • 9 Posts
        Thanks!
        This is my understanding of Screen nam:
        &tpl=`twitter-feed-tpl`

        I am using Revolution. and I'll give your code a try.
        WBR
          • 3749
          • 24,544 Posts
          No, the twitter-feed-tpl has nothing to do with the user name. You would want this in your getFeed snippet tag (replace BobRay with your Twitter user's screen name):


          &url=`http :/ / twitter.com/statuses/user_timeline/BobRay.rss`



          (I had to put extra spacess in the URL to keep the forum software from mangling it -- remove them)



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting