Twitter Streaming API confusion - twitter

I am completely confused by Twitter streaming API behavior. I created a simple stream with a 1 follow for "ESPN:
and get this tweet ( see attached) . which is a retweet, but the original is "ESPN FC" , not "ESPN"
what the heck is going on here ? Why does twitter streaming API return this status ?
{ "extended_entities": { "media": [ { "display_url": "pic.twitter.com/y2E7ktezgd", "source_user_id": 18091004, "type": "photo", "media_url": "http://pbs.twimg.com/media/ECfRaipX4AA-_-S.jpg", "source_status_id": 1164129284480483329, "url": "<placeholder_url>",
"indices": [ 44, 67 ], "sizes": { "small": { "w": 544, "h": 680, "resize": "fit" }, "large": { "w": 1080, "h": 1350, "resize": "fit" }, "thumb": { "w": 150, "h": 150, "resize": "crop" }, "medium": { "w": 960, "h": 1200, "resize": "fit" } }, "id_str":
"1164129282605703168", "expanded_url": "https://twitter.com/ESPNFC/status/1164129284480483329/photo/1", "source_status_id_str": "1164129284480483329", "media_url_https": "https://pbs.twimg.com/media/ECfRaipX4AA-_-S.jpg", "id": 1164129282605703168, "source_user_id_str":
"18091004" } ] }, "in_reply_to_status_id_str": null, "in_reply_to_status_id": null, "created_at": "Wed Aug 21 14:19:49 +0000 2019", "in_reply_to_user_id_str": null, "source": "<a href=\ "http://twitter.com/download/iphone\" rel=\ "nofollow\">Twitter for iPhone<\/a>",
"retweeted_status": {
"extended_entities": {
"media": [
{
"display_url": "pic.twitter.com/y2E7ktezgd",
"indices": [
32,
55
],
"sizes": {
"small": {
"w": 544,
"h": 680,
"resize": "fit"
},
"large": {
"w": 1080,
"h": 1350,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 960,
"h": 1200,
"resize": "fit"
}
},
"id_str": "1164129282605703168",
"expanded_url": "https://twitter.com/ESPNFC/status/1164129284480483329/photo/1",
"media_url_https": "https://pbs.twimg.com/media/ECfRaipX4AA-_-S.jpg",
"id": 1164129282605703168,
"type": "photo",
"media_url": "http://pbs.twimg.com/media/ECfRaipX4AA-_-S.jpg",
"url": "<url>"
}
]
},
"in_reply_to_status_id_str": null,
"in_reply_to_status_id": null,
"created_at": "Wed Aug 21 10:57:04 +0000 2019",
"in_reply_to_user_id_str": null,
"source": "<a href=\"https://www.spredfast.com/\" rel=\"nofollow\">Spredfast app<\/a>",
"retweet_count": 2773,
"retweeted": false,
"geo": null,
"filter_level": "low",
"in_reply_to_screen_name": null,
"is_quote_status": false,
"id_str": "1164129284480483329",
.....
}
}

This is not really an answer but an observation. Twitter appears to link all accounts that begin with ESPN.
Type this URL into a browser https://twitter.com/ESPN/status/1164129284480483329
It will forward you to the original tweet at https://twitter.com/ESPNFC/status/1164129284480483329
The same occurs with non-ESPN user "ESPNSUCKS"
https://twitter.com/ESPNSUCKS/status/1164129284480483329
And also with XESPN which is a suspended account
https://twitter.com/XESPN/status/1164129284480483329

Related

Tweepy - Differences with status info delivered by Twitter API

Does somebody knows why Twitter API delivers different information for the same status using different methods?
I'm working on a Twitter bot to collect transit events. I'm facing some issues with the information delivered by the API, due to I've identified that depending on the method, the API can deliver different result for the same Tweet/status.
Here an example for the Tweet ID:1531517617562951682 using api.get_status, the status doesn't have the attributes extended_tweet and timestamp_ms.
Thanks in advance.
{
"created_at": "Tue May 31 06:07:08 +0000 2022",
"id": 1531517617562951682,
"id_str": "**1531517617562951682**",
"text": "01:07 #Precauci\u00f3nVial | Por percance en Av. Ing. Eduardo Molina a la altura de Av. Talism\u00e1n, col. San Pedro el Chic\u2026 (**removed_url)",
**"truncated": true**,
"entities": {
"hashtags": [
{
"text": "Precauci\u00f3nVial",
"indices": [
6,
21
]
}
],
"symbols": [],
"user_mentions": [],
"urls": [
{
"url": **removed_url_short,
"expanded_url": ,
"display_url": ,
"indices": [
117,
140
]
}
]
},
"source": "Twitter Web App",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 166594238,
"id_str": "166594238",
"name": "OVIAL_SSCCDMX",
"screen_name": "OVIALCDMX",
"location": "Liverpool #136, Col. Ju\u00e1rez",
"description": "Centro de Orientaci\u00f3n Vial de la Secretar\u00eda de Seguridad Ciudadana de la Ciudad de M\u00e9xico.",
"url":,
"entities": {
"url": {
"urls": [
{
"url": ,
"expanded_url": ,
"display_url": "ssc.cdmx.gob.mx",
"indices": [
0,
23
]
}
]
},
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 1866313,
"friends_count": 125,
"listed_count": 4188,
"created_at": "Wed Jul 14 15:00:43 +0000 2010",
"favourites_count": 2748,
"utc_offset": null,
"time_zone": null,
"geo_enabled": true,
"verified": true,
"statuses_count": 1110675,
"lang": null,
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url":
"profile_background_image_url_https": ,
"profile_background_tile": false,
"profile_image_url": ,
"profile_image_url_https": ,
"profile_banner_url": ,
"profile_link_color": "BC8F8F",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none",
"withheld_in_countries": []
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"possibly_sensitive_appealable": false,
"lang": "es"
}
Same status collected with a stream.Attributes extended_tweet and timestamp are present on the status:
{
"created_at": "Tue May 31 06:07:08 +0000 2022",
"id": 1531517617562951682,
"id_str": "1531517617562951682",
"text": "01:07 #Precauci\u00f3nVial | Por percance en Av. Ing. Eduardo Molina a la altura de Av. Talism\u00e1n, col. San Pedro el Chic\u2026 (**removed url)",
"display_text_range": [
0,
140
],
"source": "Twitter Web App",
"truncated": true,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 166594238,
"id_str": "166594238",
"name": "OVIAL_SSCCDMX",
"screen_name": "OVIALCDMX",
"location": "Liverpool #136, Col. Ju\u00e1rez",
"url": "http://ssc.cdmx.gob.mx",
"description": "Centro de Orientaci\u00f3n Vial de la Secretar\u00eda de Seguridad Ciudadana de la Ciudad de M\u00e9xico.",
"translator_type": "none",
"protected": false,
"verified": true,
"followers_count": 1866203,
"friends_count": 125,
"listed_count": 4188,
"favourites_count": 2748,
"statuses_count": 1110325,
"created_at": "Wed Jul 14 15:00:43 +0000 2010",
"utc_offset": null,
"time_zone": null,
"geo_enabled": true,
"lang": null,
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "000000",
"profile_background_image_url": ,
"profile_background_image_url_https": ,
"profile_background_tile": false,
"profile_link_color": "BC8F8F",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"profile_image_url": ,
"profile_image_url_https": ,
"profile_banner_url": ,
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null,
"withheld_in_countries": []
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"extended_tweet": {
"full_text": "01:07 #Precauci\u00f3nVial | Por percance en Av. Ing. Eduardo Molina a la altura de Av. Talism\u00e1n, col. San Pedro el Chico, servicios de emergencia acuden al lugar. (**removed url)",
"display_text_range": [
0,
158
],
"entities": {
"hashtags": [
{
"text": "Precauci\u00f3nVial",
"indices": [
6,
21
]
}
],
"urls": [],
"user_mentions": [],
"symbols": [],
"media": [
{
"id": 1531517217703092224,
"id_str": "1531517217703092224",
"indices": [
159,
182
],
"additional_media_info": {
"monetizable": false
},
"media_url": ,
"media_url_https": ,
"url":,
"display_url": "pic.twitter.com/q3seKvyPIM",
"expanded_url": ,
"type": "video",
"video_info": {
"aspect_ratio": [
16,
9
],
"duration_millis": 4003,
"variants": [
{
"content_type": "application/x-mpegURL",
"url": ""
},
{
"bitrate": 832000,
"content_type": "video/mp4",
"url": "
},
{
"bitrate": 256000,
"content_type": "video/mp4",
"url":
}
]
},
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 640,
"h": 360,
"resize": "fit"
},
"medium": {
"w": 640,
"h": 360,
"resize": "fit"
},
"small": {
"w": 640,
"h": 360,
"resize": "fit"
}
}
}
]
},
"extended_entities": {
"media": [
{
"id": 1531517217703092224,
"id_str": "1531517217703092224",
"indices": [
159,
182
],
"additional_media_info": {
"monetizable": false
},
"media_url": ,
"media_url_https": ,
"url": ,
"display_url": ,
"expanded_url": ,
"type": "video",
"video_info": {
"aspect_ratio": [
16,
9
],
"duration_millis": 4003,
"variants": [
{
"content_type": "application/x-mpegURL",
"url": "
},
{
"bitrate": 832000,
"content_type": "video/mp4",
"url": "
},
{
"bitrate": 256000,
"content_type": "video/mp4",
"url": ""
}
]
},
"sizes": {
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 640,
"h": 360,
"resize": "fit"
},
"medium": {
"w": 640,
"h": 360,
"resize": "fit"
},
"small": {
"w": 640,
"h": 360,
"resize": "fit"
}
}
}
]
}
},
"quote_count": 0,
"reply_count": 0,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [
{
"text": "Precauci\u00f3nVial",
"indices": [
6,
21
]
}
],
"urls": [
{
"url": ,
"expanded_url": ,
"display_url": "twitter.com/i/web/status/1\u2026",
"indices": [
117,
140
]
}
],
"user_mentions": [],
"symbols": []
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "es",
"**timestamp_ms**": "1653977228905"
}
For v1.1, the extended Tweet information is available by default in the streaming API, but for the REST endpoints, you need to add the tweet_mode=extended parameter to your request to retrieve the full text.
In V2, there is no longer a concept of extended (beyond 140 characters) Tweets. All Tweets are natively up to 280 characters as standard.

Highchart-export-server not showing plot band correctly on chart

Plot bands in highchart export server is not working properly. I want the output same as shown in jsfiddle below.
I want the color plot band to show on y axis with width 20.
This is expected output: https://jsfiddle.net/vc6r8y3n/
Attached image is actual output when we use high-chart export server.
but when I tried same JavaScript json object on
http://export.highcharts.com/
its giving me image with plot band color spread on whole chart. its not considering width for 'y' or 'x' axis in export server. I gave attached image of export chart.
Why highchart behaving differently in both the cases.
Highchart JSON is same as in JSfiddle.
Actual image.
Expected is what it display in Jsfiddle. https://jsfiddle.net/vc6r8y3n/
{
"chart": {
"height": 350,
"width": 600,
"style": {
"fontFamily": "\"Arial\", sans-serif",
"fontSize": "16px"
},
"backgroundColor": "transparent"
},
"title": {
"text": null
},
"credits": {
"enabled": false
},
"legend": {
"align": "center",
"layout": "horizontal",
"verticalAlign": "bottom",
"symbolHeight": 5,
"symbolWidth": 5,
"symbolRadius": 0,
"itemDistance": 10,
"itemStyle": {
"fontSize": "5px",
"fontWeight": "bold",
"fontFamily": "\"Arial\", sans-serif"
},
"borderWidth": 0,
"padding": 0,
"margin": 5
},
"xAxis": {
"categories": [
"Sep-2020",
"Oct-2020",
"Nov-2020",
"Dec-2020",
"Jan-2021",
"Feb-2021"
],
"labels": {
"style": {
"fontSize": "4px",
"fontFamily": "\"Arial\", sans-serif",
"color": "#000"
},
"y": 5
},
"gridLineColor": "transparent",
"gridLineWidth": 0,
"minorGridLineWidth": 0,
"lineColor": "#9A9A9A",
"zIndex": 9999999
},
"yAxis": [
{
"title": {
"text": ""
},
"min": 0,
"max": 100,
"tickInterval": 20,
"plotBands": [
{
"color": "rgb(204,0,0)",
"from": 0,
"to": 30.99,
"zIndex": 3
},
{
"color": "rgb(226,113,113)",
"from": 31,
"to": 44.99,
"zIndex": 3
},
{
"color": "rgb(247,209,34)",
"from": 45,
"to": 54.99,
"zIndex": 3
},
{
"color": "rgb(136,207,136)",
"from": 55,
"to": 68.99,
"zIndex": 3
},
{
"color": "rgb(68,180,68)",
"from": 69,
"to": 87.99,
"zIndex": 3
},
{
"color": "rgb(0,153,0)",
"from": 88,
"to": 100,
"zIndex": 3
}
],
"width": 20
}
],
"plotOptions": {
"column": {
"dataLabels": {
"enabled": true
}
}
},
"series": [
{
"name": "Line1",
"type": "column",
"data": [
{
"y": 61,
"color": "#5b9bd5"
},
{
"y": 41,
"color": "#5b9bd5"
},
{
"y": 21,
"color": "#5b9bd5"
},
{
"y": 81,
"color": "#5b9bd5"
},
{
"y": 31,
"color": "#5b9bd5"
},
{
"y": 71,
"color": "#5b9bd5"
}
],
"color": "#5b9bd5",
"showInLegend": true
},
{
"name": "Line 2",
"type": "column",
"data": [
null,
null,
null,
null,
null,
1
],
"color": "#00B050"
},
{
"name": "Line 3",
"type": "spline",
"data": [
null,
{
"y": 45
},
{
"y": 38
},
{
"y": 32
},
{
"y": 40
},
{
"y": 48
}
],
"color": "#9A0229"
}
]
}
enter image description here

Mapping JSON Response to Model

New to the notion of Rails mapping, and would love to get some help on this from the stack overflow community.
Currently I have this JSON response from the Embedly API and don't really know how to map it to my very simple 'posts' model. I'm trying to get the image/title/url from the JSON response and map it into my database in the relevant fields, so in the JSON response below these would be 'original_url', 'image' and 'title'.
{
"provider_url": "http://piccsy.com",
"authors": [],
"provider_display": "piccsy.com",
"related": [],
"favicon_url": "http://piccsy.com/favicon.ico",
"keywords": [],
"app_links": [],
"original_url": "http://piccsy.com/2015/02/rihanna-sharks-harpers-bazaar-march-2015-photoshoot3",
"media": {},
"content": null,
"entities": [],
"provider_name": "Piccsy",
"type": "html",
"description": "Beautiful, inspirational and creative images from Piccsy. Thousands of Piccs from all our streams, for you to browse, enjoy and share with a friend.",
"embeds": [],
"images": [
{
"width": 728,
"url": "http://img2.piccsy.com/cache/images/56/8f/bed__396d8_cecf850824130_99f-post.jpg",
"height": 1092,
"caption": null,
"colors": [
{
"color": [
190,
211,
212
],
"weight": 0.3095703125
},
{
"color": [
114,
159,
171
],
"weight": 0.247314453125
},
{
"color": [
0,
52,
68
],
"weight": 0.244140625
},
{
"color": [
25,
99,
117
],
"weight": 0.198974609375
}
],
"entropy": 5.94797179868,
"size": 318918
},
{
"width": 200,
"url": "http://piccsy.com/piccsy/images/layout/logo/e02f43.200x200.jpg",
"height": 200,
"caption": null,
"colors": [
{
"color": [
215,
51,
67
],
"weight": 0.701904296875
},
{
"color": [
250,
252,
252
],
"weight": 0.298095703125
}
],
"entropy": 0.686638083774,
"size": 18691
}
],
"safe": true,
"offset": null,
"cache_age": 86065,
"lead": null,
"language": null,
"url": "http://piccsy.com/2015/02/rihanna-sharks-harpers-bazaar-march-2015-photoshoot3",
"title": "Rihanna-sharks-harpers-bazaar-march-2015-photoshoot3",
"favicon_colors": [
{
"color": [
208,
37,
38
],
"weight": 0.000244140625
},
{
"color": [
0,
0,
0
],
"weight": 0.000244140625
}
],
"published": null
}
My posts model contains very simple name, url and image fields which are all accepting strings. Any help on mapping this to a model would be brilliant, up till now I've only done very simple JSON responses and this one is a bit out of my league.
Thanks for your time.
You can just parse json response, and get required fields from it
json_response = '{your json response from api}'
response_hash = JSON.parse(json_response)
MyModel.create!(url: response_hash[:original_url], title: response_hash[:title])
But there is problem with images, response contains multiple images, so probably you should have ImageModel that belongs to MyModel, and MyModel has_many ImageModels.
Then you can do:
model = MyModel.create!(url: response_hash[:original_url], title: response_hash[:title])
response_hash[:images].each do |image|
model.images.create!(url: image[:url])
end

Parsing JSON with Ruby on Rails

I suspect this is a fairly basic concept, but two days of trial and error, google searches, and random keyboard mashing have worn me down. I'm attempting to parse JSON returned from a URL, but I'm running into an issue that I suspect is related to the array inside the JSON.
What am I doing wrong?
JSON:
{
"HotelInformationResponse": {
"#hotelId": "106347",
"customerSessionId": "0ABAA83F-4430-B291-3432-E0A2DC790CA0",
"HotelImages": {
"#size": "16",
"HotelImage": [
{
"hotelImageId": 4694179,
"name": "",
"category": 1,
"type": 0,
"caption": "Exterior",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_44_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_44_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694182,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_47_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_47_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694171,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_36_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_36_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694174,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_39_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_39_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694168,
"name": "",
"category": 3,
"type": 0,
"caption": "Guest Room",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_33_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_33_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694173,
"name": "",
"category": 3,
"type": 0,
"caption": "Guest Room",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_38_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_38_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694177,
"name": "",
"category": 3,
"type": 0,
"caption": "Guest Room",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_42_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_42_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694165,
"name": "",
"category": 10,
"type": 0,
"caption": "Restaurant",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_30_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_30_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694166,
"name": "",
"category": 10,
"type": 0,
"caption": "Restaurant",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_31_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_31_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 6601500,
"name": "",
"category": 11,
"type": 0,
"caption": "Interior",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_56_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_56_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694176,
"name": "",
"category": 12,
"type": 0,
"caption": "Pool",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_41_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_41_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694170,
"name": "",
"category": 12,
"type": 0,
"caption": "Pool",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_35_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_35_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694172,
"name": "",
"category": 12,
"type": 0,
"caption": "Pool",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_37_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_37_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694180,
"name": "",
"category": 21,
"type": 0,
"caption": "Lounge/Bar",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_45_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_45_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694181,
"name": "",
"category": 21,
"type": 0,
"caption": "Lounge/Bar",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_46_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_46_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694175,
"name": "",
"category": 38,
"type": 0,
"caption": "Suite",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_40_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_40_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
}
]
}
}
}
My simplified code:
api = Expedia::Api.new
response = api.get_information({:hotelId => '106347'})
data = response.body
parsed = JSON.parse(data.to_json)
thumbnail = parsed['HotelInformationResponse']['HotelImages']['HotelImage']['thumbNailUrl']
This returns an error "no implicit conversion of String into Integer" at the thumbnail line. I understand that the JSON lists more then one 'thumbNailUrl', and I need to specify with I'm requesting, but I'm not sure how. I would just like to retrieve the first 'thumbNailUrl'.
Incidentally, the EAN API gem I'm using is located here: https://github.com/zaidakram/expedia
This line parsed['HotelInformationResponse']['HotelImages'] gives you an Array of Hash. So you need to access each Hash inside the array by index(s). Thus you need to go as below :-
parsed['HotelInformationResponse']['HotelImages']['HotelImage'][0]['thumbnailUrl']
If you want to get all thumbnails then, iterate over it as
thumbnails = parsed['HotelInformationResponse']['HotelImages']['HotelImage'].map do |hash|
hash[thumbnailUrl]
end
To get the first hotel image you can do:
thumbnail = parsed['HotelInformationResponse']['HotelImages']['HotelImage'][0]['thumbNailUrl']
If you wanted to get all the thumbnails you can do something like:
thumbnails = []
parsed['HotelInformationResponse']['HotelImages']['HotelImage'].each { |thumbnail| thumbnails << thumbnail['thumNailUrl'] }

Fetch photos from Instagram

Currently I'm able to fetch the photos of the logged in user in my app. But I want to fetch the photos from my instagram developer account in which I have registered my app. Is this possible? Currently,
NSString *urlString=[NSString stringWithFormat:#"https://api.instagram.com/v1/users/self/feed/?access_token=%#",appDelegate.instagram.accessToken];
fetches the detail of the logged in user. But I want to get the photos from my client's instagram account. Replacing 'self' in the above url with client's username doesn't work. Any ideas ?
Can't you use the /users/user-id/media/recent Endpoint?
Example from Instagram API Documentation, to get Feed for UserID = 3, use following
https://api.instagram.com/v1/users/3/media/recent/?access_token=ACCESS-TOKEN
Returns
{
"data": [{
"comments": {
"data": [],
"count": 0
},
"caption": {
"created_time": "1296710352",
"text": "Inside le truc #foodtruck",
"from": {
"username": "kevin",
"full_name": "Kevin Systrom",
"type": "user",
"id": "3"
},
"id": "26621408"
},
"likes": {
"count": 15,
"data": [{
"username": "mikeyk",
"full_name": "Mike Krieger",
"id": "4",
"profile_picture": "..."
}, {...subset of likers...}]
},
"link": "http://instagr.am/p/BWrVZ/",
"user": {
"username": "kevin",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
"id": "3"
},
"created_time": "1296710327",
"images": {
"low_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_5.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_7.jpg",
"width": 612,
"height": 612
}
},
"type": "image",
"users_in_photo": [],
"filter": "Earlybird",
"tags": ["foodtruck"],
"id": "22721881",
"location": {
"latitude": 37.778720183610183,
"longitude": -122.3962783813477,
"id": "520640",
"street_address": "",
"name": "Le Truc"
}
},
{
"videos": {
"low_resolution": {
"url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_102.mp4",
"width": 480,
"height": 480
},
"standard_resolution": {
"url": "http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_101.mp4",
"width": 640,
"height": 640
},
"comments": {
"data": [{
"created_time": "1279332030",
"text": "Love the sign here",
"from": {
"username": "mikeyk",
"full_name": "Mikey Krieger",
"id": "4",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1242695_75sq_1293915800.jpg"
},
"id": "8"
},
{
"created_time": "1279341004",
"text": "Chilako taco",
"from": {
"username": "kevin",
"full_name": "Kevin S",
"id": "3",
"profile_picture": "..."
},
"id": "3"
}],
"count": 2
},
"caption": null,
"likes": {
"count": 1,
"data": [{
"username": "mikeyk",
"full_name": "Mikeyk",
"id": "4",
"profile_picture": "..."
}]
},
"link": "http://instagr.am/p/D/",
"created_time": "1279340983",
"images": {
"low_resolution": {
"url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_5.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_7.jpg",
"width": 612,
"height": 612
}
},
"type": "video",
"users_in_photo": null,
"filter": "Vesper",
"tags": [],
"id": "363839373298",
"user": {
"username": "kevin",
"full_name": "Kevin S",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
"id": "3"
},
"location": null
},
]
}
Instagram only provides the API to get the feeds of self .. Have a look on
https://api.instagram.com/v1/users/userID/media/recent
this i hope it provides some recent medias of a user for more info look at this
http://instagram.com/developer/api-console/

Resources