1

I'm using the dukt.net Twitter plugin, in a Matrix field. It works fine locally, but on our dev server, something odd is happening, when I enter a Tweet url, like:

https://twitter.com/POLITICOEurope/status/596249628892364800

It fetches the tweet from the API correctly, but then displays it in the CP and in the templates as:

https://twitter.com/POLITICOEurope/status/5.96249628892E+17

So it converts it to a float. However, in the "fields_tweets_tweet" field in the database, it lists the correct long ID: 596249628892364800

And the odd thing is that it's happening on the dev server, but not locally. Anyone an idea where to start?

2

Pretty sure PHP is interpreting that string as an int. Doing a var_dump on the variable shows int(596249628892364800). That's pretty much PHP's type casting at work.

While you could cast the variable as a string, there's actually an unused variable called id_str which is ideal to use.

Edit the file twitter\fieldtypes\Twitter_TweetFieldType.php. Replace line 48 from:

$url = 'https://twitter.com/'.$tweet['user']['screen_name'].'/status/'.$tweet['id'];

To:

$url = 'https://twitter.com/'.$tweet['user']['screen_name'].'/status/'.$tweet['id_str'];
6
  • Thanks crawf, this must be pretty close to the solution.. But the result is still the same. It seems the conversion to float, has already happened before that line, so after grabbing it out of the db.. Not sure where this happens though. – tom May 7 '15 at 14:01
  • Hmm - are you able to do a var_dump($tweet['id']); around line 46? And that still prints out the float value? – crawf May 7 '15 at 14:03
  • Actually - just updated my answer using an existing field in that $tweet array! – crawf May 7 '15 at 14:20
  • great, now it's working perfectly. Can you tell me where you found this id_str existence? I can't find it anywhere – tom May 7 '15 at 16:13
  • Awesome! I basically just used var_dump($tweet) to see what the object was containing. It has a id and id_str attribute, among many other things. – crawf May 7 '15 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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