1

I try to display My recent tweets,

I using Twitter API 1.1 Client for Wordpress

Check Twitter Result

Display My name is working,

But display My recent tweet is not working!

I want solution, this is My code:

<?php 

require_once (TEMPLATEPATH . '/include/twitter-api/twitter-api.php'); 

$credentials = array(
'consumer_key'    =>  'i added my consumer_key',
'consumer_secret' =>  'i added my consumer_secret'
);

$twitter_api = new Wp_Twitter_Api( $credentials );

$query = 'screen_name=twitter_api&count=1';
$args = array(
    'type' => 'statuses/user_timeline',
    'cache' => ( 24 * 60 * 60 )
);
$result = $twitter_api->query( $query, $args );
echo $result->name; // it's working and I got my name
echo '<br>';
echo $result->text; // it's not working and I don't got my recent tweets, I want solution!
?>
0

I guess there's more than one problem here.

1) With 'type' set to 'statuses/user_timeline' $result->name is not supposed to return any value because as you can verify with twitter api console (http://bit.ly/twapiconsole) 'statuses/user_timeline' will return an array of tweets.

2) I'm not sure you're familiar with PHP but you cannot echo an array of data but you have to loop trough the array with a foreach loop:

// Your code here
// ...

$result = $twitter_api->query( $your_query, $your_args );
foreach ( $result as $tweet ){
    echo $tweet->text;
}

3) When you have doubt on how to handle an API request response just do a var_dump($result)

I hope I was of some help.

  • Thanks Mr. MiCc83, I will try it. – user3492381 Sep 15 '14 at 8:19
  • I set count=3, but i got 1 tweet only. – user3492381 Sep 15 '14 at 8:34
  • Using bit.ly/twapiconsole how many tweets you get with statuses/user_timeline ? Could you paste the full code (with no $credentials off course)? – MiCc83 Sep 15 '14 at 11:03
  • Mr.Micc now is working, thanks for help & for your class. – user3492381 Sep 15 '14 at 23:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.