Fetch Image & External URL from Tweets with statuses/user_timeline API - twitter

I wish to extract value for External URL present in the Tweet. Plus the generated Thumbnail of that URL.
Example Tweet:
http://prntscr.com/ogdqey
https://twitter.com/JarirBookstore/status/1151506848387870720
Output from Twitter statuses/user_timeline API -
{
"created_at": "Wed Jul 17 15:00:01 +0000 2019",
"id": 1151506848387870720,
"id_str": "1151506848387870720",
"full_text": "عروض #صيف_هواوي على أجهزة التابلت والميت بوك المختلفة \nالعرض ساري الى 21 يوليو",
"truncated": false,
"display_text_range": [
0,
78
],
"entities": {
"hashtags": [
{
"text": "صيف_هواوي",
"indices": [
5,
15
]
}
],
"symbols": [],
"user_mentions": [],
"urls": []
},
"source": "<a href=\"https:\/\/ads-api.twitter.com\" rel=\"nofollow\">Twitter Ads Composer<\/a>",
"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": 281376243,
"id_str": "281376243"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 3,
"favorited": false,
"retweeted": false,
"lang": "ar"
},
URL entity is a blank array. If the link is not present in the Tweet's text itself, API doesn't return it in the URL entity. I've tried with and without tweet_mode=extended
Surprisingly, Twitter does return URL for few such Tweets. One example is below.
https://twitter.com/BillGates/status/1150605518291001345
API Response:
{
"created_at": "Mon Jul 15 03:18:27 +0000 2019",
"id": 1150605518291001345,
"id_str": "1150605518291001345",
"full_text": "I recently wrote about how people with tech skills can find fascinating problems to work on in global health and development. I was excited to come across this #techreview article about African machine learning researchers who are already doing just that. https:\/\/t.co\/3e1d2QvvH4",
"truncated": false,
"display_text_range": [
0,
279
],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [
{
"screen_name": "techreview",
"name": "MIT Technology Review",
"id": 15808647,
"id_str": "15808647",
"indices": [
160,
171
]
}
],
"urls": [
{
"url": "https:\/\/t.co\/3e1d2QvvH4",
"expanded_url": "https:\/\/b-gat.es\/2xMsbdh",
"display_url": "b-gat.es\/2xMsbdh",
"indices": [
256,
279
]
}
]
},
"source": "<a href=\"https:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>",
"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": 50393960,
"id_str": "50393960"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 1320,
"favorite_count": 6719,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
},
Why the response is random? It does return URL for Bill Gates' Tweet but not for the one mentioned earlier in my question.
How can I have both External URL and the Thumbnail displayed by Twitter?
My final API call -
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=jarirbookstore&count=100&exclude_replies=true&trim_user=true&include_rts=false&tweet_mode=extended

The first of the two examples you provide is posted by the Twitter Ads platform, so the attached card is not part of the Tweet. There is no way to get that via the API. In the second case, the URL is part of the Tweet text, so it is also part of the URL entities object.

Related

Shopify products/delete webhook only returns ID

My ruby on rails app is supposed to do some things whenever a product is deleted. According to Shopify's website here the response to products/delete is supposed to be a JSON object with information such as the product_id associated with the product that was deleted:
{
"id": 788032119674292922,
"title": "Example T-Shirt",
"body_html": null,
"vendor": "Acme",
"product_type": "Shirts",
"created_at": null,
"handle": "example-t-shirt",
"updated_at": "2021-07-01T14:08:43-04:00",
"published_at": "2021-07-01T14:08:43-04:00",
"template_suffix": null,
"published_scope": "web",
"tags": "example, mens, t-shirt",
"admin_graphql_api_id": "gid:\/\/shopify\/Product\/788032119674292922",
"variants": [
{
"id": 642667041472713922,
"product_id": 788032119674292922,
"title": "",
"price": "19.99",
"sku": "example-shirt-s",
"position": 0,
"inventory_policy": "deny",
"compare_at_price": "24.99",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Small",
"option2": null,
"option3": null,
"created_at": null,
"updated_at": null,
"taxable": true,
"barcode": null,
"grams": 200,
"image_id": null,
"weight": 200.0,
"weight_unit": "g",
"inventory_item_id": null,
"inventory_quantity": 75,
"old_inventory_quantity": 75,
"requires_shipping": true,
"admin_graphql_api_id": "gid:\/\/shopify\/ProductVariant\/642667041472713922"
},
{
"id": 757650484644203962,
"product_id": 788032119674292922,
"title": "",
"price": "19.99",
"sku": "example-shirt-m",
"position": 0,
"inventory_policy": "deny",
"compare_at_price": "24.99",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Medium",
"option2": null,
"option3": null,
"created_at": null,
"updated_at": null,
"taxable": true,
"barcode": null,
"grams": 200,
"image_id": null,
"weight": 200.0,
"weight_unit": "g",
"inventory_item_id": null,
"inventory_quantity": 50,
"old_inventory_quantity": 50,
"requires_shipping": true,
"admin_graphql_api_id": "gid:\/\/shopify\/ProductVariant\/757650484644203962"
}
],
"options": [
{
"id": 527050010214937811,
"product_id": 788032119674292922,
"name": "Title",
"position": 1,
"values": [
"Small",
"Medium"
]
}
],
"images": [
{
"id": 539438707724640965,
"product_id": 788032119674292922,
"position": 0,
"created_at": null,
"updated_at": null,
"alt": null,
"width": 323,
"height": 434,
"src": "\/\/cdn.shopify.com\/shopifycloud\/shopify\/assets\/shopify_shirt-39bb555874ecaeed0a1170417d58bbcf792f7ceb56acfe758384f788710ba635.png",
"variant_ids": [
],
"admin_graphql_api_id": "gid:\/\/shopify\/ProductImage\/539438707724640965"
}
],
"image": null
}
However, whenever I go to test it by actually deleting a product in the Shopify Admin interface, I'm only getting the id in my response. Anybody know why this is happening? My setup for the other webhooks is the exact same and I'm not having any other issues.
Seems like this is an open issue on the shopify_api gem for version 2021-01. I don't think you are doing anything wrong. It looks like nobody has responded in a while to the issue, you might want to try to upgrade to another version to see if they fixed it in any of the newer versions.
EDIT: According to a post from 3/2017 the expected behaviour from deleted endpoints is to only return the ID of the resource that was deleted. This could be why the issue on Github is being ignored.

Can I detect whether or not a Jenkins build has finished based on a queue URL?

I am trying to trigger a Jenkins build and wait until it has completed.
When I start Jenkins via its REST API, I get a resonse with a URL like http://JENKINS_URL:8080/queue/item/36285/.
When I try to access it, I always the get the 404 error. My test builds are rather short therefore it is possible that they are finished before I exit the debugger.
Question: Is it guaranteed that if a URL like http://JENKINS_URL:8080/queue/item/36285/ results in a 404 response, then the corresponding Jenkins build is finished? That is, can I use this URL to find out whether or not it is finished (as long as the URL returns a status code not equal to 404, the build is running)?
The /queue/item/ give you items in queue, that waiting to start and 404 means item not in the queue, can be canceled or in execution. Job execution can be in running, finished or canceled statuses.
You can use queueId (36285 in your example), get job details and get build status for the particular queueId. In the response for the request below is job details with builds. You can find build you need by queueId in builds and get building(boolean) and result status:
JENKINS_URL+"/job/"+ artifactToBuild +"/api/json?depth=1'
Response example for JENKINS_URL+"/job/"+ artifactToBuild +"/api/json?depth=1':
{
"_class": "org.jenkinsci.plugins.workflow.job.WorkflowJob",
"actions": [],
"description": "",
"displayName": "my_job_name",
"displayNameOrNull": null,
"fullDisplayName": "my_job_name",
"fullName": "my_job_name",
"name": "my_job_name",
"url": "http://localhost:8080/job/my_job_name/",
"buildable": true,
"builds": [
{
"_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions": [],
"artifacts": [],
"building": false,
"description": null,
"displayName": "#1",
"duration": 1651,
"estimatedDuration": 1671,
"executor": null,
"fullDisplayName": "my_job_name #1",
"id": "1",
"keepLog": false,
"number": 1,
"queueId": 103,
"result": "SUCCESS",
"timestamp": 1580946018635,
"url": "http://localhost:8080/job/my_job_name/1/",
"changeSets": [],
"culprits": [],
"nextBuild": {
"number": 2,
"url": "http://localhost:8080/job/my_job_name/2/"
},
"previousBuild": null
}
],
"color": "aborted",
"firstBuild": {},
"healthReport": [
{
"description": "Build stability: No recent builds failed.",
"iconClassName": "icon-health-80plus",
"iconUrl": "health-80plus.png",
"score": 100
}
],
"inQueue": false,
"keepDependencies": false,
"lastBuild": {
"_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions": [],
"artifacts": [],
"building": false,
"description": null,
"displayName": "#10",
"duration": 1238044,
"estimatedDuration": 1671,
"executor": null,
"fullDisplayName": "my_job_name #10",
"id": "10",
"keepLog": false,
"number": 10,
"queueId": 587,
"result": "ABORTED",
"timestamp": 1581534463735,
"url": "http://localhost:8080/job/my_job_name/10/",
"changeSets": [],
"culprits": [],
"nextBuild": null,
"previousBuild": {
"number": 9,
"url": "http://localhost:8080/job/my_job_name/9/"
}
},
"lastCompletedBuild": {
"_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions": [],
"artifacts": [],
"building": false,
"description": null,
"displayName": "#10",
"duration": 1238044,
"estimatedDuration": 1671,
"executor": null,
"fullDisplayName": "my_job_name #10",
"id": "10",
"keepLog": false,
"number": 10,
"queueId": 587,
"result": "ABORTED",
"timestamp": 1581534463735,
"url": "http://localhost:8080/job/my_job_name/10/",
"changeSets": [],
"culprits": [],
"nextBuild": null,
"previousBuild": {
"number": 9,
"url": "http://localhost:8080/job/my_job_name/9/"
}
},
"lastFailedBuild": null,
"lastStableBuild": {
"_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions": [],
"artifacts": [],
"building": false,
"description": null,
"displayName": "#2",
"duration": 1671,
"estimatedDuration": 1671,
"executor": null,
"fullDisplayName": "my_job_name #2",
"id": "2",
"keepLog": false,
"number": 2,
"queueId": 105,
"result": "SUCCESS",
"timestamp": 1580946027378,
"url": "http://localhost:8080/job/my_job_name/2/",
"changeSets": [],
"culprits": [],
"nextBuild": {
"number": 3,
"url": "http://localhost:8080/job/my_job_name/3/"
},
"previousBuild": {
"number": 1,
"url": "http://localhost:8080/job/my_job_name/1/"
}
},
"lastSuccessfulBuild": {
"_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions": [],
"artifacts": [],
"building": false,
"description": null,
"displayName": "#2",
"duration": 1671,
"estimatedDuration": 1671,
"executor": null,
"fullDisplayName": "my_job_name #2",
"id": "2",
"keepLog": false,
"number": 2,
"queueId": 105,
"result": "SUCCESS",
"timestamp": 1580946027378,
"url": "http://localhost:8080/job/my_job_name/2/",
"changeSets": [],
"culprits": [],
"nextBuild": {
"number": 3,
"url": "http://localhost:8080/job/my_job_name/3/"
},
"previousBuild": {
"number": 1,
"url": "http://localhost:8080/job/my_job_name/1/"
}
},
"lastUnstableBuild": null,
"lastUnsuccessfulBuild": {
"_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions": [],
"artifacts": [],
"building": false,
"description": null,
"displayName": "#10",
"duration": 1238044,
"estimatedDuration": 1671,
"executor": null,
"fullDisplayName": "my_job_name #10",
"id": "10",
"keepLog": false,
"number": 10,
"queueId": 587,
"result": "ABORTED",
"timestamp": 1581534463735,
"url": "http://localhost:8080/job/my_job_name/10/",
"changeSets": [],
"culprits": [],
"nextBuild": null,
"previousBuild": {
"number": 9,
"url": "http://localhost:8080/job/my_job_name/9/"
}
},
"nextBuildNumber": 11,
"property": [
{
"_class": "hudson.plugins.jira.JiraProjectProperty"
},
{
"_class": "org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty"
}
],
"queueItem": null,
"concurrentBuild": false,
"resumeBlocked": false
}
Make a POST request to /jenkins/job/YOURJOBNAME/build. The response
contains a location header with the queue id.
Every X seconds, make a GET request to
/jenkins/job/YOURJOBNAME/api/json?tree=builds[building,number,result,queueId].
The response contains an array of builds for the specified job. Here
you can filter a build by the queueId, and check its status.
The build object can give you a lot of info, but the most important is the number. The number is the id of the build, which you can use later to reference it.
(Just an example) - Download all build artifacts:
/jenkins/job/YOURJOBNAME/THEBUILDNUMBER/artifact/*zip*/artifacts.zip

How to fetch specific details from the result of twitter api?

With twitter api named GET friends/list, https://api.twitter.com/1.1/friends/list.json i could get details of every user i am following. What i need is some particular data, 'geo' and 'coordinates' to be specific. There do exist a parameter named 'skip_status=true' to skip the status. But please let me know if either 'geo and coordinates' or 'status' alone could be fetched.
"users": [
{
"id": 3233xxxxxx,
"id_str": "3233428303",
"name": "Mars",
"screen_name": "Mars9411",
"location": "",
"description": "",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 1,
"friends_count": 0,
"listed_count": 0,
"created_at": "Tue Jun 02 09:58:03 +0000 2015",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": true,
"verified": false,
"statuses_count": 9,
"lang": "en",
"status": {
"created_at": "Tue Oct 27 12:31:11 +0000 2015",
"id": 6589842841878xxxx,
"id_str": "65898428418781xxxx",
"text": "Hey, Download the app in your phone and you can have an Emergency Contact for FREE. It's Great.\nhttps://t.co/kEZg",
"source": "iOS",
"truncated": false,
"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,
"geo": {
"type": "Point",
"coordinates": [
28.612486,
77.377425
]
},
"coordinates": {
"type": "Point",
"coordinates": [
77.377425,
28.612486
]
},
"place": {
"id": "2e6064382c71b343",
"url": "https://api.twitter.com/1.1/geo/id/2e606438.json",
"place_type": "city",
"name": "Noida",
"full_name": "Noida, Uttar Pradesh",
"country_code": "IN",
"country": "India",
"contained_within": [],
"bounding_box": {
"type": "Polygon",
"coordinates": [
[
[
77.302126,
28.4439811
],
[
77.6953257,
28.4439811
],
[
77.6953257,
28.6471308
],
[
77.302126,
28.6471308
]
]
]
},
"attributes": {}
},
"contributors": null,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": [
{
"url": "https://t.co/kEZ",
"expanded_url": "http://www.sav.net/apps",
"display_url": "sav.net/apps",
"indices": [
101,
124
]
}
]
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
},
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_0_normal.png",
"profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_0_normal.png",
"profile_link_color": "0084B4",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"has_extended_profile": false,
"default_profile": true,
"default_profile_image": true,
"following": true,
"follow_request_sent": false,
"notifications": false,
"muting": false,
"blocking": false,
"blocked_by": false
},
{
"id": 741xxxxxx,
"id_str": "741xxxxxx",
"name": "Food",
"screen_name": "food",
"location": "Fort, IN",
"description": "Locally xxxxx",
"url": "http://t.co",
"entities": {
"url": {
"urls": [
{
"url": "http://t.co",
"expanded_url": "http://Food.com",
"display_url": "food.com",
"indices": [
0,
22
]
}
]
},
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 1976,
"friends_count": 375,
"listed_count": 44,
"created_at": "Tue Aug 07 02:10:46 +0000 2012",
"favourites_count": 247,
"utc_offset": -14400,
"time_zone": "Eastern Time (US & Canada)",
"geo_enabled": true,
"verified": false,
"statuses_count": 1349,
"lang": "en",
"status": {
"created_at": "Sun Oct 25 01:52:10 +0000 2015",
"id": 658098694xxxxxxxxx,
"id_str": "658098694xxxxxxxxx",
"text": "#BenjamenKelly tonight!",
"source": "Twitter for iPhone",
"truncated": false,
"in_reply_to_status_id": 657368006075486200,
"in_reply_to_status_id_str": "657368006075486208",
"in_reply_to_user_id": 509529431,
"in_reply_to_user_id_str": "509529431",
"in_reply_to_screen_name": "Kelly",
"geo": null,
"coordinates": null,
"place": {
"id": "3877d6c867447819",
"url": "https://api.twitter.com/1.1/geo/id/3877d6c867447819.json",
"place_type": "city",
"name": "Fort",
"full_name": "Fort, IN",
"country_code": "US",
"country": "United States",
"contained_within": [],
"bounding_box": {
"type": "Polygon",
"coordinates": [
[
[
-85.336872,
40.95926
],
[
-85.003231,
40.95926
],
[
-85.003231,
41.214574
],
[
-85.336872,
41.214574
]
]
]
},
"attributes": {}
},
"contributors": null,
"retweet_count": 0,
"favorite_count": 1,
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [
{
"screen_name": "Benj",
"name": "boy",
"id": 509529431,
"id_str": "509529431",
"indices": [
0,
14
]
}
],
"urls": []
},
"favorited": false,
"retweeted": false,
"lang": "en"
},
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/2479745010/yz4eu6wrca8c5e2hw6x9_normal.jpeg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/2479745010/yz4eu6wrca8c5e2hw6x9_normal.jpeg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/741935389/1444260221",
"profile_link_color": "0084B4",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"has_extended_profile": false,
"default_profile": true,
"default_profile_image": false,
"following": true,
"follow_request_sent": false,
"notifications": false,
"muting": false,
"blocking": false,
"blocked_by": false
}
This is what i am getting(supposing i have only 2 users in my following). What i need is as follows:
"geo": {
"type": "Point",
"coordinates": [
28.612486,
77.377425
]
},
"coordinates": {
"type": "Point",
"coordinates": [
77.377425,
28.612486
]
},
"geo": null,
"coordinates": null,
You need to filter out those details from the results yourself. The API will return the complete person object, not specific fields.

Twitter Geo Tagging

I am trying to download tweets from the London area using
curl --user xx:xx -X POST -d 'locations=-0.651,51.208,0.425,51.781' https://stream.twitter.com/1.1/statuses/filter.json > twitter.london.json
I am getting tweets that are way off. For example in (-6.71658144,50.48812681). Why is that?
The tweet:
{
"created_at": "Mon Apr 08 12:26:40 +0000 2013",
"id": 321237656321286144,
"id_str": "321237656321286144",
"text": "4dc9c54f70000000",
"source": "\u003ca href=\"http:\/\/www.google.com\/\" rel=\"nofollow\"\u003eGoogle\u003c\/a\u003e",
"truncated": false,
"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": 61043461,
"id_str": "61043461",
"name": "GooGuns",
"screen_name": "googuns_prod",
"location": "",
"url": null,
"description": null,
"protected": false,
"followers_count": 86,
"friends_count": 0,
"listed_count": 2,
"created_at": "Tue Jul 28 22:49:22 +0000 2009",
"favourites_count": 0,
"utc_offset": -18000,
"time_zone": "Eastern Time (US & Canada)",
"geo_enabled": true,
"verified": false,
"statuses_count": 417708,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png",
"profile_background_image_url_https": "https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png",
"profile_background_tile": false,
"profile_image_url": "http:\/\/a0.twimg.com\/sticky\/default_profile_images\/default_profile_3_normal.png",
"profile_image_url_https": "https:\/\/si0.twimg.com\/sticky\/default_profile_images\/default_profile_3_normal.png",
"profile_link_color": "0084B4",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"default_profile": true,
"default_profile_image": true,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": {
"type": "Point",
"coordinates": [50.48812681, -6.71658144]
},
* * "coordinates": {
"type": "Point",
"coordinates": [-6.71658144, 50.48812681]
},
* * "place": {
"id": "6416b8512febefc9",
"url": "http:\/\/api.twitter.com\/1\/geo\/id\/6416b8512febefc9.json",
"place_type": "country",
"name": "United Kingdom",
"full_name": "United Kingdom",
"country_code": "GB",
"country": "United Kingdom",
"contained_within": [],
"geometry": null,
"polylines": [],
"bounding_box": {
"type": "Polygon",
"coordinates": [
[
[-8.662663, 49.1626564],
[-8.662663, 60.86165],
[1.768926, 60.86165],
[1.768926, 49.1626564]
]
]
},
"attributes": {}
},
"contributors": null,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [],
"urls": [],
"user_mentions": []
},
"favorited": false,
"retweeted": false,
"filter_level": "medium",
"lang": "en"
}
According to the Twitter documentation, the location parameter accepts a comma separated list of longitude,latitude pairs specifying a set of bounding boxes.
If you just pass in a single latitude and longitude, then it will return the nearest Tweets to that location. Have you also specified a filter query, if so this will be massively cutting down the number of Tweets returned, meaning that the closest Tweet to London, is actually miles away. I had a similar problem.
Having said that, I just tried this out, if you use the lat and lon below, with NO other filter queries it works well.
{locations: [51.50,0.12,51.75,1.25]}
Another point to note, is that not a lot of Tweets actually have locations attached anymore, and often the ones which do are very inaccurate as they can actually be coming from the authors home location specified on their profile.

Getting only selected fields of user timeline from Twitter API

I am getting user's timeline from an iOS app, with a big number of tweets being pulled from the API. I am using the statuses/user_timeline endpoint to get the data, however, as I'm on a mobile device and as I only need the tweet text only, I'd like to filter only the actual text data of the tweets. I've already set include_entities to no and trim_user to true, but even with entities and user data trimmed off, I'm still getting a lot of data that I don't need. Here is a sample tweet that I get from the endpoint:
{
"created_at": "Tue Nov 27 14:13:13 +0000 2012",
"id": 273429272209801200,
"id_str": "273429272209801217",
"text": "you could list #5ThingsIFindAttractive but you can actually find them on Facebook with Social Match on iPhone! http://t.co/zRr1ggbz",
"source": "web",
"truncated": false,
"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": 62828168,
"id_str": "62828168"
},
"geo": null,
"coordinates": null,
"place": {
"id": "682c5a667856ef42",
"url": "http://api.twitter.com/1/geo/id/682c5a667856ef42.json",
"place_type": "country",
"name": "Turkey",
"full_name": "Turkey",
"country_code": "TR",
"country": "Turkey",
"bounding_box": {
"type": "Polygon",
"coordinates": [
[
[
25.663883,
35.817497
],
[
44.822762,
35.817497
],
[
44.822762,
42.109993
],
[
25.663883,
42.109993
]
]
]
},
"attributes": {}
},
"contributors": null,
"retweet_count": 0,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false
}
The only thing I actually need is the text key of the dictionary. The rest is currently useless for my app. I'll be requesting LOTS of tweets like this. How can I send a request to just to pull of the text key of the tweets? Currently, this method is extremely inefficient.
You can't. The best you can do is set up a proxy which will request the data, strip it back, and then forward it to the mobile.
If it's any consolation, the JSON will be gzip'd and so should still be relatively small - so won't take too long to transfer or eat in to the user's data allowance.

Resources