0

I want to get status from twitter to display on my site.

Here is the code

<?php

function getTwitterStatus($userid){
$url = "https://api.twitter.com/1/statuses/user_timeline/$userid.xml?
count=1&include_rts=1callback=?";

$xml = simplexml_load_file($url) or die("could not connect");

foreach($xml->status as $status){
$text = $status->text;
}
echo $text;
}

getTwitterStatus("soksovat");

?>

I want to get 1 status from userid = "soksovat", but when i run the above, two warnings are come out:

  1. Warning: simplexml_load_file(https://api.twitter.com/1/statuses/user_timeline/soksovat.xml?count=1&include_rts=1callback=?) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 410 Gone in .......... line 6
  2. Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "https://api.twitter.com/1/statuses/user_timeline/soksovat.xml?count=1&include_rts=1callback=?" in .............. line 6 count not connect

Can anyone help to solve this problem? I got stuck with it several day ago.

Thank in advance.

Sovat
  • 59
  • 1
  • 8
  • Going to the actual file gives the following message: `The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.`. Meaning you need to update. – MisterBla Aug 15 '13 at 07:23
  • You're using the Twitter API 1.0. It's deprecated. Use 1.1. – Frederik Spang Aug 15 '13 at 07:22

1 Answers1

1

You have to update your old Twitter API 1.0 to Twitter API 1.1.

New Twitter API : https://dev.twitter.com/docs/api/1.1/overview

Get User Timeline : https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

Useful Twitter API v1.1 Class :

https://github.com/J7mbo/twitter-api-php/blob/master/TwitterAPIExchange.php

som
  • 4,650
  • 2
  • 21
  • 36
  • i already update to use twitter api 1.1, but when i run code above that such warnings still happen. do you know why? – Sovat Aug 15 '13 at 08:13
  • @Sovat You can't just put "1.1" in the URL and that's it. Read [this post](http://stackoverflow.com/questions/12916539/simplest-php-example-for-retrieving-user-timeline-with-twitter-api-version-1-1/15314662#15314662) - you need to make **authenticated requests**. – Jimbo Aug 15 '13 at 09:25
  • @Sovat Your url not saying that you are update twitter API version. – som Aug 15 '13 at 13:02