PHPでtwitter API + TwitterOAuthを使用してキーワードにあった投稿を取得し、
webサイトに掲載したいと考えています。
投稿の全体は取得できたのですが、
各投稿に表示されている画像や動画のオブジェクトがどこにあるのかわかりません。
色々なサイトで調べたところ、entities->urlsにあるようなことが書かれているのですが、
実際にアクセスしてみても見つけることができません。
各投稿の画像や動画の取得方法を教えていただけるようお願いいたします。
php
require 'vendor/autoload.php'; use Abraham\TwitterOAuth\TwitterOAuth; $consumer_key = '**************'; $consumer_secret = '**************'; $access_token = '**************'; $access_token_secret = '**************'; $connection = new TwitterOAuth( $consumer_key, $consumer_secret, $access_token, $access_token_secret ); $hash_params = ['count' => 20,'q' => '#ニュース', 'lang'=>'ja']; $tweets = $connection->get('search/tweets', $hash_params)->statuses; $list = []; for($i = 0 ; $i < count($tweets) ; $i++){ $url = 'https://twitter.com/sj/status/'.$tweets[$i]->id;,//投稿URL $list[$i]=[ 'date' => $tweets[$i]->created_at,//投稿日 'screen_name'=>'@'.$tweets[$i]->user->screen_name,//ユーザーネーム 'id' => $tweets[$i]->id,//投稿ID 'txt' => $tweets[$i]->text,//投稿内容 'url' => $url, 'user_image' => $tweets[$i]->user->profile_image_url_https,//ユーザーイメージ ]; } var_dump( $list); var_dump( $tweets);
下記実際に取得されたソース($twitter)の一部です
php
array (size=20) 0 => object(stdClass)[7] public 'created_at' => string 'Thu Jun 24 00:40:14 +0000 2021' (length=30) public 'id' => int 1407861087723155457 public 'id_str' => string '1407861087723155457' (length=19) public 'text' => string '京都市、医療・介護等の統合データを活用した分析事業を推進[#ニュース] https://t.co/0dIqeJ6xe6' (length=123) public 'truncated' => boolean false public 'entities' => object(stdClass)[17] public 'hashtags' => array (size=1) ... public 'symbols' => array (size=0) ... public 'user_mentions' => array (size=0) ... public 'urls' => array (size=1) ... public 'metadata' => object(stdClass)[19] public 'iso_language_code' => string 'ja' (length=2) public 'result_type' => string 'recent' (length=6) public 'source' => string '<a href="https://mobile.twitter.com" rel="nofollow">Twitter Web App</a>' (length=71) public 'in_reply_to_status_id' => null public 'in_reply_to_status_id_str' => null public 'in_reply_to_user_id' => null public 'in_reply_to_user_id_str' => null public 'in_reply_to_screen_name' => null public 'user' => object(stdClass)[20] public 'id' => int 1341034975177523200 public 'id_str' => string '1341034975177523200' (length=19) public 'name' => string 'デジタル行政' (length=18) public 'screen_name' => string 'digitalgyosei' (length=13) public 'location' => string '' (length=0) public 'description' => string 'デジタル化を旗振る全ての行政職員向け情報サイト。国・自治体による行政のデジタル化事例をテーマにした情報を、インタビューやニュース情報として提供。' (length=216) public 'url' => string 'https://t.co/y7ELiGpqm9' (length=23) public 'entities' => object(stdClass)[23] ... public 'protected' => boolean false public 'followers_count' => int 42 public 'friends_count' => int 9 public 'listed_count' => int 0 public 'created_at' => string 'Mon Dec 21 14:57:54 +0000 2020' (length=30) public 'favourites_count' => int 2 public 'utc_offset' => null public 'time_zone' => null public 'geo_enabled' => boolean false public 'verified' => boolean false public 'statuses_count' => int 90 public 'lang' => null public 'contributors_enabled' => boolean false public 'is_translator' => boolean false public 'is_translation_enabled' => boolean false public 'profile_background_color' => string 'F5F8FA' (length=6) public 'profile_background_image_url' => null public 'profile_background_image_url_https' => null public 'profile_background_tile' => boolean false public 'profile_image_url' => string 'http://pbs.twimg.com/profile_images/1341068542330896389/OC1h1TuN_normal.png' (length=75) public 'profile_image_url_https' => string 'https://pbs.twimg.com/profile_images/1341068542330896389/OC1h1TuN_normal.png' (length=76) public 'profile_banner_url' => string 'https://pbs.twimg.com/profile_banners/1341034975177523200/1609125668' (length=68) public 'profile_link_color' => string '1DA1F2' (length=6) public 'profile_sidebar_border_color' => string 'C0DEED' (length=6) public 'profile_sidebar_fill_color' => string 'DDEEF6' (length=6) public 'profile_text_color' => string '333333' (length=6) public 'profile_use_background_image' => boolean true public 'has_extended_profile' => boolean true public 'default_profile' => boolean true public 'default_profile_image' => boolean false public 'following' => boolean false public 'follow_request_sent' => boolean false public 'notifications' => boolean false public 'translator_type' => string 'none' (length=4) public 'withheld_in_countries' => array (size=0) ... public 'geo' => null public 'coordinates' => null public 'place' => null public 'contributors' => null public 'is_quote_status' => boolean false public 'retweet_count' => int 0 public 'favorite_count' => int 0 public 'favorited' => boolean false public 'retweeted' => boolean false public 'possibly_sensitive' => boolean false public 'lang' => string 'ja' (length=2) 1 =>
まだ回答がついていません
会員登録して回答してみよう