URL for Tweet Text not in Search API results

urls

#1

I’m new to the Twitter API, but I’ve done my due diligence and searched the JSON results for the original URL that links to each Tweet. (I’m converting the JSON into a CSV file.) There may be close to a dozen URLs, but none of them are for the original tweet. Can someone please help me understand how I can make this possible? This will be a regular part of my visualization work… linking back to the original tweet.

Sample of start of JSON returned:

{“statuses”:[{“created_at”:“Wed Jun 07 14:57:18 +0000 2017”,“id”:872467508992720896,“id_str”:“872467508992720896”,“text”:“RT @PreferredNetJP: \u3010\u8b1b\u6f14\u3011#ICRA2017 \u30ef\u30fc\u30af\u30b7\u30e7\u30c3\u30d7 “Learning and Control for Autonomous Manipulation Systems”\u3067\u6628\u5e74\u5ea6\u306ePFN\u30a4\u30f3\u30bf\u30fc\u30f3\u8349\u91ce\u3055\u3093\u304c\u7814\u7a76\u6210\u679c\u3092\u767a\u8868\uff01\n\u30b0\u30ea\u30c3\u30d1\u30fc\u30cf\u30f3\u30c9\u3067\u8272\u3093\u306a\u2026”,“truncated”:false,“entities”:{“hashtags”:[{“text”:“ICRA2017”,“indices”:[24,33]}],“symbols”:[],“user_mentions”:


#2

The Tweet object does not contain that information.

You do get back the unique Tweet ID, and the username of the user that posted it, though - so in this case you could use https://twitter.com/ + username + /statuses/ + id_str to reconstruct a URL that would show you the original Tweet on twitter.com.


#3

Thx Andy for the lead! This still isn’t working. Using the following info. as an example (and I’ve tried many others), the tweet doesn’t exist:
Note: I tried both /status/ and /statuses/ b/w the username (user_screen_name) and id_str (statuses_id_str)

EXAMPLE:

statuses__id_str statuses__user__screen_name statuses__text
870850263401103000 kmoriyama RT @AutomatonBlog: Video Friday: Robot Dance Teacher, Transformer Drone, and Pneumatic Reel Actuator https://t.co/0tOJX8c124 #icra2017 http…


#4

Is this what you’re looking for?


#5

Yes it is! I’m looking for the original tweet url, and your example shows that. I can’t seem to parse how to do this and I’ve literally combed through the 100 or so fields the Search API produces. Thx for any help if you can explain this.


#6

Literally just took “id_str” value and added it to https://twitter.com/statuses/

Are you asking how to parse that JSON string?


#7

Thx Dan for walking through this. I found the issue. The automated tool to convert the json to csv (https://json-csv.com/) is changing the id_str value! At the very end of the values, it seems to scrub the numbers and replace with 3 zeroes. (i.e. id_str 873102196849614848 changes to 873102196849614000). So lesson learned to look at the output more closely. I was just thrown by the slightly difference field name in the output (statuses_id_str) and not knowing what I was looking at since this is my first rodeo.

So I’ve contacted the developer, since the output is correct on the web interface at json-csv.com BEFORE I download it to a CSV. Something is apparently happening in the conversion, where the numbers are changed.

Any advice on how to simply parse the JSON myself (since this is ultimately what I think I need to learn)? I am very motivated to get this right and use the Twitter API regularly. thx again.


#8

This is probably the most simple solution.

<?php
$json = ''; // put your json string in the quotes.
$array = json_decode($json, true);
print_r($array);
?>

#9

The reason that Tweet objects contain both an id and an id_str value is that some languages, notably Javascript, cannot handle very large numbers, and will mangle them exactly as you describe. The _str value is intentionally returned as a string, not a large integer, to avoid this behaviour, so I’m surprised that the tool you mention is behaving in this way. If you’re interested in more detail on this, see our page on snowflake IDs.

If you can resolve this issue, then either the solution Daniel describes, or the one that I described (including the screen name of the user in the URL), should work consistently.


#10

Thx to both of you. The developer for the json-csv tool sent a link that identified the issue was with excel and open office. A simple fix (thankfully) is to open the csv file in Google Sheets, copy the id_str and paste in a “text” formatted excel cell as text. And we’re in business! I’ll look at these other solutions moving forward. Thx again for addressing this.

cheers!