Archived Forum Post

Index of archived forum posts

Question:

Twitter API search results

Jun 24 '13 at 10:38

I'm using the HTTP component to search the Twitter API. Everything is working and I am receiving data back, but I can't seem to access the json object I am receiving. How do I get the data? http.BGResultString is empty and I only know I am receiving data because of the output of http.SessionLogFilename ->

---- Sending ----
GET /1.1/search/tweets.json?q=%23wedding&result_type=recent&include_entities=1&count=1 HTTP/1.1
Authorization: OAuth oauth_consumer_key="xxxxxxxxx", oauth_nonce="xxxxxxxx", oauth_signature="xxxxx", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371684429", oauth_token="xxxxxxx", oauth_version="1.0"
Host: api.twitter.com

---- Received ----
HTTP/1.1 200 OK
cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
content-length: 2939
content-type: application/json;charset=utf-8
date: Wed, 19 Jun 2013 23:26:58 GMT
expires: Tue, 31 Mar 1981 05:00:00 GMT
last-modified: Wed, 19 Jun 2013 23:26:58 GMT
pragma: no-cache
server: tfe
set-cookie: lang=en
set-cookie: guest_id=v1%3A137168441868850584; Domain=.twitter.com; Path=/; Expires=Fri, 19-Jun-2015 23:26:58 UTC
status: 200 OK
strict-transport-security: max-age=631138519
x-access-level: read-write
x-frame-options: SAMEORIGIN
x-rate-limit-limit: 180
x-rate-limit-remaining: 177
x-rate-limit-reset: 1371684565
x-transaction: fc0b7fce6089c9ca
x-xss-protection: 1; mode=block

{"statuses":[{"metadata":{"result_type":"recent","iso_language_code":"en"},"created_at":"Wed Jun 19 23:26:43 +0000 2013","id":347495689892286464,"id_str":"347495689892286464","text":"8MM Tungsten Gold Two Tone Cross Celtic Engrave Ring SZ 12 $29.99 http:\/\/t.co\/nJqMzza4EG #rings #wedding","source":"\u003ca href=\"http:\/\/uTweetDeals.com\" rel=\"nofollow\"\u003eU Tweet Deals\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":1008797815,"id_str":"1008797815","name":"Jewelry Deals","screen_name":"iJewelryDeals","location":"","description":"Tweeting deals on Jewelry, diamonds, rings, necklaces, bracelets and more.  I Follow Back All Followers.","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":2579,"friends_count":2600,"listed_count":22,"created_at":"Thu Dec 13 13:14:24 +0000 2012","favourites_count":0,"utc_offset":-25200,"time_zone":"Arizona","geo_enabled":false,"verified":false,"statuses_count":81424,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/737003994\/c6498044b9c34c4dd16a2715bb34710c.jpeg","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/737003994\/c6498044b9c34c4dd16a2715bb34710c.jpeg","profile_background_tile":true,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2970432963\/59562672ba1eb5fc925731bad10a3cc3_normal.jpeg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2970432963\/59562672ba1eb5fc925731bad10a3cc3_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/1008797815\/1371151905","profile_link_color":"0084B4","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[{"text":"rings","indices":[89,95]},{"text":"wedding","indices":[96,104]}],"symbols":[],"urls":[{"url":"http:\/\/t.co\/nJqMzza4EG","expanded_url":"http:\/\/bit.ly\/11MRG4c","display_url":"bit.ly\/11MRG4c","indices":[66,88]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}],"search_metadata":{"completed_in":0.022,"max_id":347495689892286464,"max_id_str":"347495689892286464","next_results":"?max_id=347495689892286463&q=%23wedding&count=1&include_entities=1&result_type=recent","query":"%23wedding","refresh_url":"?since_id=347495689892286464&q=%23wedding&result_type=recent&include_entities=1","count":1,"since_id":0,"since_id_str":"0"}}

Answer

(This problem was resolved earlier in private email.)

The solution has to do with a misunderstanding of the API. When the http.UseBgThread is set to False, an HTTP method call runs synchronously and returns a result upon completion (such as a string, bool, HttpResponse object, etc.). However, when the http.UseBgThread is True, the method is started in a background thread and it returns immediately. The return value should be ignored. Once the background task completes, the return value can be obtained from the property or method that corresponds to the return type of the method. For example, the QuickGetStr method returns a string, therefore the async result is available in the BgResultString property. Here's a list of return types and the corresponding property/method used to access the return value after an async method completes:

string: BgResultString property
byte array: BgResultData property
HttpResponse object: BgResponseObject method
bool: BgTaskSuccess property
int: BgResultInt property

Note that the HttpResponse object is returned by a method call, not a property.