2 Replies Latest reply on May 25, 2016 9:16 AM by wearekonstruct

    Coldfusion and Twitter JSON

    wearekonstruct

      Hi there,

       

      I am running the following code I found on the internet to grab a load of Tweets with a particular hashtag:

       

          <cfset consumerKey = "MY_CONSUMER_KEY">

          <cfset consumerSecret = "MY_CONSUMER_SECRET">

          <cfset bearerToken = ToBase64(consumerKey & ":" & consumerSecret)>

          <cfset authorization = "Basic " & bearerToken>

          

          <cfhttp url="https://api.twitter.com/oauth2/token" method="post" charset="utf-8">

              <cfhttpparam type="header" name="Authorization" value="#authorization#">

              <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded;charset=UTF-8">

              <cfhttpparam type="body" value="grant_type=client_credentials">

          </cfhttp>

          

          <cfset bearerTokenResponse = DeserializeJSON(cfhttp.fileContent)>

          <cfset authorization2 = "Bearer " & bearerTokenResponse.access_token>

          

          <cfhttp url="https://api.twitter.com/1.1/search/tweets.json" method="get" charset="utf-8">

              <cfhttpparam type="header" name="Authorization" value="#authorization2#">

              <cfhttpparam type="url" name="q" value="%23ColdFusion">

          </cfhttp>

       

      Obviously I have put in my own keys in the consumerkey & consumersecret variables.

       

      {"statuses":[{"created_at":"Tue May 17 16:32:17 +0000 2016","id":732609696109080577,"id_str":"732609696109080577","text":"Well done Team Konstruct! \n\n#konstruct\n#pvd\n#suncity\n#dunhill https:\/\/t.co\/yRUPIXmQ6t","truncated":false,"entities":{"hashtags":[{"text":"konstruct" ,"indices":[28,38]},{"text":"pvd","indices":[39,43]},{"text":"suncity","indices":[44,52]}, {"text":"dunhill","indices":[53,61]}],"symbols":[],"user_mentions":[],"urls":[{"url":"http s:\/\/t.co\/yRUPIXmQ6t","expanded_url":"http:\/\/fb.me\/3kyQTnmLe","display_url":"fb.me\/3 kyQTnmLe","indices":[62,85]}]},"metadata":{"iso_language_code":"en","result_type":"recent" },"source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","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":238145671,"id_str":"238145671","name":"Vincent Viljoen","screen_name":"konstructdesign","location":"Brackenfell, Cape Town","description":"I design and build exhibition stands. I love it when my clients win awards for their stands and their brands stand out because of my creativity...","url":"http:\/\/t.co\/soGTwPlFhi","entities":{"url":{"urls":[{"url":"http: \/\/t.co\/soGTwPlFhi","expanded_url":"http:\/\/konstruct.co.za","display_url":"konstruct.c o.za","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":5 89,"friends_count":1973,"listed_count":18,"created_at":"Fri Jan 14 13:36:08 +0000 2011","favourites_count":0,"utc_offset":7200,"time_zone":"Pretoria","geo_enabled":true,"v erified":false,"statuses_count":1863,"lang":"en","contributors_enabled":false,"is_translat or":false,"is_translation_enabled":false,"profile_background_color":"131516","profile_back ground_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme14\/bg.gif","profile_backg round_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme14\/bg.gif","profile _background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/14657 48472\/VW_1_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images \/1465748472\/VW_1_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_bann ers\/238145671\/1369226061","profile_link_color":"009999","profile_sidebar_border_color":" FFFFFF","profile_sidebar_fill_color":"EFEFEF","profile_text_color":"333333","profile_use_b ackground_image":true,"has_extended_profile":false,"default_profile":false,"default_profil e_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":nul l,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_cou nt":0,"favorite_count":0,"favorited":false,"retweeted":false,"possibly_sensitive":false,"l ang":"en"}],"search_metadata":{"completed_in":0.015,"max_id":732609696109080577,"max_id_st r":"732609696109080577","query":"%2523konstruct","refresh_url":"?since_id=7326096961090805 77&q=%2523konstruct&include_entities=1","count":15,"since_id":0,"since_id_str":"0"}}

       

      I have searched endlessly for weeks in the way that I can use this to display in a legible way. So for instance, suppose I wanted to output on the page, the actual tweet(s), the handle of who posted the tweet and the date - how!!! It is driving me mad as I am sure I did something like this before but can't remember how!

       

      Many thanks in advance.

       

      J