見ていただいてありがとうございます。
表題の通り、自分のtwitter投稿をJSON形式で取得しRailsを使用してサイトに掲載しようとしています。
ユーザー名・投稿文言・投稿日時は正常に表示できるのですが、画像を表示しようとすると以下のエラーが発生します。
・エラーメッセージ:private method `entities' called for #<Twitter::Tweet id=****>
Did you mean? entities?
controller
class TwitterController < ApplicationController require 'twitter' def index @client = Twitter::REST::Client.new do |config| config.consumer_key = '****' config.consumer_secret = '****' config.access_token = '****' config.access_token_secret = '****' end end end
index.html.erb
<!DOCTYPE html> <html> <head> <title>TwitterRails</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <% @client.home_timeline.each do |tweet| %> <%= tweet.created_at %><br> <%= tweet.entities.media[0].media_url %><br> <%= tweet.user.name + ':' + tweet.text %><br> <% end %> </body> </html>
twitter API Console Toolで取得しているJSON
[ { "created_at": "Tue Apr 12 10:42:23 +0000 2016", "id": 719838064634253300, "id_str": "719838064634253314", "text": "きれいだね~\n#夜景 https://t.co/xoKu25hPH4", "entities": { "hashtags": [ { "text": "夜景", "indices": [ 7, 10 ] } ], "symbols": [], "user_mentions": [], "urls": [], "media": [ { "id": 719838063757643800, "id_str": "719838063757643777", "indices": [ 11, 34 ], "media_url": "http://pbs.twimg.com/media/Cf1g57YUUAElSLI.jpg", "media_url_https": "https://pbs.twimg.com/media/Cf1g57YUUAElSLI.jpg", "url": "https://t.co/xoKu25hPH4", "display_url": "pic.twitter.com/xoKu25hPH4", "expanded_url": "http://twitter.com/tanaka24177269/status/719838064634253314/photo/1", "type": "photo", "sizes": { "medium": { "w": 600, "h": 377, "resize": "fit" }, "thumb": { "w": 150, "h": 150, "resize": "crop" }, "small": { "w": 340, "h": 214, "resize": "fit" }, "large": { "w": 960, "h": 603, "resize": "fit" } } } ] },
エラー内容の「entities」をコピペしても同様のエラーが出てしまい、画像が表示されない状態です。
どうすれば画像が正常に表示されるのかご教示お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/25 02:27