How do you find a user's twitter id from a user's twitter username in Android -
in android app, want users able enter twitter username , there twitter app launches on entered username's page. did research , found out link needed open twitter app app twitter://user?user_id=id_num wondering if there way user's twitter id twitter username in android can make happen. appreciated, thank you.
you should read through twitter api, in particular section user lookups
that particular request has optional fields search id or screen_name , return list of matches can parse user ids. can search screen_name , read response id.
the request looking is:
get https://api.twitter.com/1/users/lookup.json?screen_name=somename
the provided response in api examples is:
[ { "name": "twitter api", "profile_sidebar_border_color": "87bc44", "profile_background_tile": false, "profile_sidebar_fill_color": "e0ff92", "location": "san francisco, ca", "profile_image_url": "http://a3.twimg.com/profile_images/689684365/api_normal.png", "created_at": "wed may 23 06:01:13 +0000 2007", "profile_link_color": "0000ff", "favourites_count": 2, "url": "http://apiwiki.twitter.com", "contributors_enabled": true, "utc_offset": -28800, "id": 6253282, "profile_use_background_image": true, "profile_text_color": "000000", "protected": false, "followers_count": 160752, "lang": "en", "verified": true, "profile_background_color": "c1dfee", "geo_enabled": true, "notifications": false, "description": "the real twitter api. tweet api changes, service issues , appily answer questions twitter , our api. don't answer? it's on website.", "time_zone": "pacific time (us & canada)", "friends_count": 19, "statuses_count": 1858, "profile_background_image_url": "http://a3.twimg.com/profile_background_images/59931895/twitterapi-background-new.png", "status": { "coordinates": null, "favorited": false, "created_at": "tue jun 22 16:53:28 +0000 2010", "truncated": false, "text": "@demonicpagan possible part of signature generation incorrect & fails real reasons.. follow on list if suspect", "contributors": null, "id": 16783999399, "geo": null, "in_reply_to_user_id": 6339722, "place": null, "source": "<a href="http://www.tweetdeck.com" rel="nofollow">tweetdeck</a>", "in_reply_to_screen_name": "demonicpagan", "in_reply_to_status_id": 16781827477 }, "screen_name": "twitterapi", "following": false }, { "name": "twitter", "profile_sidebar_border_color": "eeeeee", "profile_background_tile": false, "profile_sidebar_fill_color": "f6f6f6", "location": "san francisco, ca", "profile_image_url": "http://a1.twimg.com/profile_images/878669694/twitter_bird_normal.jpg", "created_at": "tue feb 20 14:35:54 +0000 2007", "profile_link_color": "038543", "favourites_count": 2, "url": "http://twitter.com", "contributors_enabled": true, "utc_offset": -28800, "id": 783214, "profile_use_background_image": true, "profile_text_color": "333333", "protected": false, "followers_count": 3305606, "lang": "en", "verified": true, "profile_background_color": "acded6", "geo_enabled": true, "notifications": false, "description": "always wondering what's happening. ", "time_zone": "pacific time (us & canada)", "friends_count": 257, "statuses_count": 774, "profile_background_image_url": "http://s.twimg.com/a/1276896641/images/themes/theme18/bg.gif", "status": { "coordinates": null, "favorited": false, "created_at": "tue jun 22 16:40:19 +0000 2010", "truncated": false, "text": "9 cool things twitter account (via @pastemagazine) http://bit.ly/c0ldc6", "contributors": [ 16739704 ], "id": 16783169544, "geo": null, "in_reply_to_user_id": null, "place": null, "source": "web", "in_reply_to_screen_name": null, "in_reply_to_status_id": null }, "screen_name": "twitter", "following": false } ]
so can access id results parsing json response "id" field.
note returned json array of results , not single definitive answer. need work out correct 1 (order not guaranteed either not assume first entry likely).
also worth noting though documented returning 'id' , integer value, current preferred usage of ids supply 'id_str' , string representation of integer. due inconsistencies in how various platforms handle , limit integers. if receive 'id' should use 'id_str' future interactions.
Comments
Post a Comment