Twitter RSS Feeds

Support requests, bug reports, etc. go here. Dedicated servers / VDS hosting only
virgo
Bear Rating Trainee
Bear Rating Trainee
Posts: 37
Joined: 12 Jun 2013, 22:14

Re: Twitter RSS Feeds

Postby virgo » 13 Jun 2013, 00:04

jdelamater99 wrote:I wonder why your install isn't doing that and mine isn't. Unless the precision is already set to a sufficiently large value in mine. I'll have to investigate that. (just checked, my precision is set to 14)


No idea. Maybe some difference in php version. I have 5.3.3 from Debian Squeeze. Or maybe it's a 32 vs 64 bit issue.

jdelamater99 wrote:Anyways, does using strval() work for you?

strval($twitter_data[$i]['id'])

If so, I'll update the code to use that.


Nope. I changed it just for id tag part and it still gave out 3.42241025379E+17 instead of 342241025378615296.
But with Googling i also found following solution:
json_decode(preg_replace ('/:\s?(\d{14,})/', ': "${1}"', $json), true);

twitterfan
Bear Rating Trainee
Bear Rating Trainee
Posts: 9
Joined: 13 Jun 2013, 01:58

Re: Twitter RSS Feeds

Postby twitterfan » 13 Jun 2013, 01:59

Hello,

I just installed this script within a .php file. The RSS-feed is now showing again, but all links lead to a wrong adress, something with statuses/3.4415234235296E+17 at the ending... and twitter writes, that this site does not exist.

What is wrong with the code? I did not change anything than the keys and username and so on.

jdelamater99
Bear Rating Master
Bear Rating Master
Posts: 109
Joined: 11 Apr 2013, 17:45

Re: Twitter RSS Feeds

Postby jdelamater99 » 13 Jun 2013, 05:37

Updated the code to $twitter_data = json_decode(preg_replace ('/:\s?(\d{14,})/', ': "${1}"', $json), true);

Thanks!

User avatar
sleeper_service
Bear Rating Overlord
Bear Rating Overlord
Posts: 884
Joined: 30 Mar 2013, 23:50
Location: Dallas, Texas

Re: Twitter RSS Feeds

Postby sleeper_service » 13 Jun 2013, 05:51

jdelamater99 wrote:If you are using the v1 Twitter API to pull in user feeds, you'll notice that it has stopped working. This is because Twitter has turned off the v1 API, which breaks RSS/ATOM feeds. Version 1.1 of the API doesn't support RSS at all.

api.twitter.com/1/statuses/user_timeline.rss?screen_name=XXXXXX <--- this no longer works

The solution isn't hard, but it will take a bit of work.


well done

Image
and thank you!

User avatar
sleeper_service
Bear Rating Overlord
Bear Rating Overlord
Posts: 884
Joined: 30 Mar 2013, 23:50
Location: Dallas, Texas

Re: Twitter RSS Feeds

Postby sleeper_service » 13 Jun 2013, 08:02

might I suggest you go back and update the original code with the code updates you've mentioned along the way.

great stuff, thanks again. working nicely here.

first post from my postgres consultant friend to test it: OH: "sub-optimal bike-cooter interface" #mtb

twitterfan
Bear Rating Trainee
Bear Rating Trainee
Posts: 9
Joined: 13 Jun 2013, 01:58

Re: Twitter RSS Feeds

Postby twitterfan » 13 Jun 2013, 11:19

@jdelamater99: Did not work for me. Maybe I did something wring?... could you please paste the whole working code again? With all needed changes/updates (of course without username and keys) them I copy & paste it and try again :-)

virgo
Bear Rating Trainee
Bear Rating Trainee
Posts: 37
Joined: 12 Jun 2013, 22:14

Re: Twitter RSS Feeds

Postby virgo » 13 Jun 2013, 11:26

twitterfan wrote:@jdelamater99: Did not work for me. Maybe I did something wring?... could you please paste the whole working code again? With all needed changes/updates (of course without username and keys) them I copy & paste it and try again :-)


He did change the original.

In original there is a line:
$twitter_data = json_decode(json, true);
change it to:
$twitter_data = json_decode(preg_replace ('/:\s?(\d{14,})/', ': "${1}"', $json), true);

It will NOT change articles, that are already imported into ttrss. It only affects next update.

jdelamater99
Bear Rating Master
Bear Rating Master
Posts: 109
Joined: 11 Apr 2013, 17:45

Re: Twitter RSS Feeds

Postby jdelamater99 » 13 Jun 2013, 15:16

sleeper_service wrote:might I suggest you go back and update the original code with the code updates you've mentioned along the way.

great stuff, thanks again. working nicely here.

first post from my postgres consultant friend to test it: OH: "sub-optimal bike-cooter interface" #mtb


twitterfan wrote:@jdelamater99: Did not work for me. Maybe I did something wring?... could you please paste the whole working code again? With all needed changes/updates (of course without username and keys) them I copy & paste it and try again :-)


Like virgo said, I have been updating the original as this thread progressed. The only thing I didn't incorporate was changing the php 'precision' setting, which was addressed by the regular expression that is applied to the json parser.

twitterfan, how exactly is it not working for you? As was mentioned by virgo, it doesn't update any existing imports, although for some of the twitter users that I follow, it downloaded the tweets as "new", but didn't do this for all of the people that I'm following by RSS.

Stepping back from that, does it work when you access it directly?
ie, server.com/PATH/filename.php?screen_name=TWITTERUSER&count=10

Does it throw any error messages?

twitterfan
Bear Rating Trainee
Bear Rating Trainee
Posts: 9
Joined: 13 Jun 2013, 01:58

Re: Twitter RSS Feeds

Postby twitterfan » 13 Jun 2013, 16:07

Hi,

yes, when opening it directly it works fine. I am using the Super Rss Reader Plugin for Wordpress, where I put in a RSS feed address. It worked and it also works with this code now - but the LINKS are wrong. When clicking on a tweet a "not found" message from twitter appears. Do you know what I mean?

twitterfan
Bear Rating Trainee
Bear Rating Trainee
Posts: 9
Joined: 13 Jun 2013, 01:58

Re: Twitter RSS Feeds

Postby twitterfan » 13 Jun 2013, 16:38

Hm, even with the changed line it does not work:

https://twitter.com/username/statuses/3 ... x88849E+17

Such links do not work. They all lead to an error site right from twitter... "Sorry, this site does not exist, we are working on it" (translated from German)...

jdelamater99
Bear Rating Master
Bear Rating Master
Posts: 109
Joined: 11 Apr 2013, 17:45

Re: Twitter RSS Feeds

Postby jdelamater99 » 13 Jun 2013, 16:43

try adding this to the top of the code. some systems my block this sort of change. but won't hurt to try it.
ini_set('precision', 20);

Code: Select all

<?php
ini_set('precision', 20);

$token = 'ACCESS_TOKEN';
$token_secret = 'ACCESS_TOKEN_SECRET';
$consumer_key = 'CONSUMER_KEY';
$consumer_secret = 'CONSUMER_SECRET';

jdelamater99
Bear Rating Master
Bear Rating Master
Posts: 109
Joined: 11 Apr 2013, 17:45

Re: Twitter RSS Feeds

Postby jdelamater99 » 13 Jun 2013, 18:02

Updated the code in the original post.

    added
    * ini_set('precision', 20); // to hopefully take care of those bigint problems
    * print('<title>@'.$twitter_data[0]['user']['screen_name'].'</title>'. PHP_EOL); // to give a title to new feed subscriptions
    * support for test=true URL variable // see the raw JSON data.
    * print('<link href="//abs.twimg.com/favicons/favicon.ico" rel="shortcut icon" type="image/x-icon" />'. PHP_EOL); // favicon for new feed subscriptions (doesn't seem to work)

    changed
    * $twitter_data[$i]['id'] to $twitter_data[$i]['id_str'] // again, to hopefully take care of the bigint problems.
    * formatted the XML output for readability

edit::

I moved added ID and ID_STR to the test output. This shows the variable type for these two. Both show as string for me, but I wonder if there's a difference for others...

virgo
Bear Rating Trainee
Bear Rating Trainee
Posts: 37
Joined: 12 Jun 2013, 22:14

Re: Twitter RSS Feeds

Postby virgo » 13 Jun 2013, 21:48

jdelamater99 wrote:I moved added ID and ID_STR to the test output. This shows the variable type for these two. Both show as string for me, but I wonder if there's a difference for others...


I temprarily removed the preg_replace from json_decode and I got

Code: Select all

id: double
id_str: string

It's double with or without ini_set('precision', 20); - difference is, that without it's presented in scientific notation.

However, are you using 32 or 64 bit php? Using 64 bit php on Linux could be reason, why you don't see that problem. 64 bit php on linux has 64 bit integer AFAIK. 32 bit php on linux and 32 or 64 bit php on Windows have 32 bit integer.

I also changed generated link tag to contain https url (because Twitter redirects to https anyway) - but left id tag as it is.

I also added

Code: Select all

    if (isset( $_GET["test"] ) && $_GET["test"] == true){
       print("<pre>");
       print_r($json);
       print("</pre>". PHP_EOL);
    }

before then

Code: Select all

$twitter_data = json_decode(preg_replace ('/:\s?(\d{14,})/', ': "${1}"', $json), true);

to see the original json data.
Not really important, but when debugging, it could be useful. And if it contains test code anyways....

jdelamater99
Bear Rating Master
Bear Rating Master
Posts: 109
Joined: 11 Apr 2013, 17:45

Re: Twitter RSS Feeds

Postby jdelamater99 » 13 Jun 2013, 23:25

virgo wrote:
jdelamater99 wrote:I moved added ID and ID_STR to the test output. This shows the variable type for these two. Both show as string for me, but I wonder if there's a difference for others...


I temprarily removed the preg_replace from json_decode and I got

Code: Select all

id: double
id_str: string

It's double with or without ini_set('precision', 20); - difference is, that without it's presented in scientific notation.

However, are you using 32 or 64 bit php? Using 64 bit php on Linux could be reason, why you don't see that problem. 64 bit php on linux has 64 bit integer AFAIK. 32 bit php on linux and 32 or 64 bit php on Windows have 32 bit integer.


That's really odd. I'm on a 64 bit system, although it's a mac server, which is really just a *nix gui (OSX is based off Debian). So the only thing that I can thing of is a difference in software versions someplace, or possibly a configuration difference. Although, at this point, it doesn't really matter, since the code has been set to work with both.

Thanks for the help with troubleshooting this.Since I couldn't replicate that, I probably never would have found it.

jdelamater99
Bear Rating Master
Bear Rating Master
Posts: 109
Joined: 11 Apr 2013, 17:45

Re: Twitter RSS Feeds

Postby jdelamater99 » 13 Jun 2013, 23:34

I modified the test routine on my local copy

Code: Select all

if (isset( $_GET["test"] )){   
   print('id: ' . gettype($twitter_data[0]['id']). '<br>'. PHP_EOL);
   print('id_str: ' . gettype($twitter_data[0]['id_str']). PHP_EOL);
   
   if ($_GET["test"] == 'json')
      $test = $json;
   else
      $test = $twitter_data;
   
   print("<pre>");
   print_r($test);
   print("</pre>". PHP_EOL);
}


When reading the raw JSON, I get this...

Code: Select all

id: string
id_str: string

[{"created_at":"Wed Jun 12 19:14:33 +0000 2013","id":344895517240737792,"id_str":"344895517240737792",...


Interesting difference.

But anyways, I think it would be safe to remove the ini_set, and the preg_replace and just use id_str, since it is already a string in the raw data. Just to remove any unessential cruft.


Return to “Support”

Who is online

Users browsing this forum: No registered users and 10 guests