Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Could use help with some php / twitter code

    So I had this code up and going, until Twitter went around and changed their code.

    I am hoping to get a little help getting it working again.

    https://github.com/chaos67731/Getting-Twitter-With-PHP/

    --
    Alos, this is about my first time adding anything to githud.com so if I have something wrong just ley me know.

  • #2
    New Coder
    Join Date
    Sep 2011
    Posts
    68
    Thanks
    0
    Thanked 7 Times in 7 Posts
    That looks like a lot of code to get a list of tweets. Have you considered using a Oath library, I am currently using this one https://github.com/abraham/twitteroauth

    Here is a sample of code I used in a previous project:

    PHP Code:
    class AJAX_get_twitter
    {
        private 
    $_oauth;

        private 
    $_comsumer_key = *************;
        private 
    $_comsumer_secret '*************';
        private 
    $_access_token '**************';
        private 
    $_access_secret '*****************';

        public function 
    __Construct ()
        {
            
    $this->_oauth = new twitteroauth $this->_comsumer_key$this->_comsumer_secret$this->_access_token$this->_access_secret );
        }

        public function 
    index ()
        {
            
    $data $this->_oauth->get 'users/show', array ( 'screen_name' => 'screen_name' ) );
            die ( 
    json_encode $data ) );
        }

        public function 
    tweets ()
        {
            
    $data $this->_oauth->get 'statuses/user_timeline', array ( 'screen_name' => 'screen_name' ) );
            die ( 
    json_encode $data ) );
        }

    This basically instantiates the twitteroauth object and returns the users info in the index method and their tweets in the tweets method.

    Sorry if this isnt what you wanted but I got a bit lost looking at your code!

    PS - Welcome to github, its a awesome tool to use!

  • #3
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by davidjones1990 View Post
    That looks like a lot of code to get a list of tweets. Have you considered using a Oath library, I am currently using this one https://github.com/abraham/twitteroauth

    Here is a sample of code I used in a previous project:

    PHP Code:
    class AJAX_get_twitter
    {
        private 
    $_oauth;

        private 
    $_comsumer_key = *************;
        private 
    $_comsumer_secret '*************';
        private 
    $_access_token '**************';
        private 
    $_access_secret '*****************';

        public function 
    __Construct ()
        {
            
    $this->_oauth = new twitteroauth $this->_comsumer_key$this->_comsumer_secret$this->_access_token$this->_access_secret );
        }

        public function 
    index ()
        {
            
    $data $this->_oauth->get 'users/show', array ( 'screen_name' => 'screen_name' ) );
            die ( 
    json_encode $data ) );
        }

        public function 
    tweets ()
        {
            
    $data $this->_oauth->get 'statuses/user_timeline', array ( 'screen_name' => 'screen_name' ) );
            die ( 
    json_encode $data ) );
        }

    This basically instantiates the twitteroauth object and returns the users info in the index method and their tweets in the tweets method.

    Sorry if this isnt what you wanted but I got a bit lost looking at your code!

    PS - Welcome to github, its a awesome tool to use!

    From what I understand of the new Twitter API I will have to get the secret/key/token stuff to be able to do this from now on. . . Kind of sucks but I guess that I have to change with times.

    It is a lot of code, and I am sure there are/were better ways to do it, I really likes it for the facts that it would give me the tweets in a nice ul/li format at the end so I could format it on a site from there also it was all done in one file so that kept less for me to keep track of.

    I should add some notes to the code to make it easy for others to see what I am doing, I am by no means I php/dev as I work most in the designing of websites and just have to work with Wordpress most of the time.

    Thanks for the link! I will take a look at the and see if I can get something working.

  • #4
    New Coder
    Join Date
    Sep 2011
    Posts
    68
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Your welcome!

    Yeh the code I gave you was just a class I use so if you only need to insert it into a document you could do this.

    PHP Code:
    $twitter = new twitteroauth 'consumer_key''consumer_secret''access_token''access_secret' );
    $data $twitter->get 'statuses/user_timeline', array ( 'screen_name' => 'screen_name' ) );

    //Then you would loop through $data and put it into a <ul>, maybe something like this

    $display '<ul>';

    foreach ( 
    $data as $tweet ) {
        
    $display .= '<li>' $tweet['text'] . '</li>';
    }

    $display .= '</ul>'
    Hope that helps


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •