我運行下面的代碼我發現在互聯網上搶推文的負載與特定主題標籤:ColdFusion和Twitter的JSON
<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>
很顯然,我已經把我自己的鍵在consumerkey & consumersecret變量。
{"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":"https:\/\/t.co\/yRUPIXmQ6t","expanded_url":"http:\/\/fb.me\/3kyQTnmLe","display_url":"fb.me\/3kyQTnmLe","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.co.za","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":589,"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,"verified":false,"statuses_count":1863,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"131516","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme14\/bg.gif","profile_background_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\/1465748472\/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_banners\/238145671\/1369226061","profile_link_color":"009999","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"EFEFEF","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"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,"lang":"en"}],"search_metadata":{"completed_in":0.015,"max_id":732609696109080577,"max_id_str":"732609696109080577","query":"%2523konstruct","refresh_url":"?since_id=732609696109080577&q=%2523konstruct&include_entities=1","count":15,"since_id":0,"since_id_str":"0"}}
我已經搜索了好幾個星期的方式,我可以用它來以可讀的方式顯示。例如,假設我想在頁面上輸出實際的推文,誰發佈了推文和日期的句柄 - 怎麼樣!這讓我很生氣,因爲我確信我之前做過類似的事情,但不記得如何!
非常感謝提前。
J
那麼你試過什麼代碼來顯示信息?你有什麼問題?如果不知道迄今爲止已經嘗試了什麼,很難提供幫助。只有提示,我可以根據你所示的是使用'DeserializeJSON()'來轉換對CF數據類型的響應。 –
你好 - 我已經嘗試了很多東西!最新版本: \t record = deserializeJSON(cfhttp.fileContent); \t writeOutput(record.statuses.id); \t \t 。基本上,如果多於一條推文回來,我如何將它們分開並以清晰的方式顯示,並顯示句柄,推文和可能的日期?我無法弄清楚如何鑽取。 –
*我嘗試了很多東西!最新的... *最好至少包含一些你在[你的問題]中嘗試過的東西(http://stackoverflow.com/posts/37408886/edit)。我們意識到它不會是完美的「工作」代碼,但是......提供一個起點可以讓人們更容易地協助和/或識別您可能遇到的問題:) – Leigh