#はじめに
PHPとTwitterOAuthのライブラリを使用し、TwitterAPIでデータを取得しようとしている際の質問になります。
使用しているのAPIの詳細は、下記の通りです。
- endpoint :
search/tweets
- parameter :
['q' => 'from:{user_name} filter:native_video' 'result_type'=>'mixed','count' => '100']
#問題
上記の内容で、TwitterAPIを叩き、取得したレスポンスを使って、インスタンスを生成しようとしています。
下記のようなツイート一つのレスポンスに対して、一つのインスタンスを生成する際に、
下記にあります extended_entities
の有る無しで、インスタンスを作るかどうか条件分岐したいのですが、どのようにすればいいかわからず困っています。
あるツイート一つのレスポンスです 0 => {#252 ▼ +"created_at": "Sun Feb 10 00:00:00 +0000 2019" +"id": 1094***************** +"id_str": "1094*****************" +"text": "テストテストテストテスt" +"truncated": false +"entities": {#247 ▶} +"extended_entities": {#227 ▶} +"metadata": {#226 ▶} +"source": "<a href="http://twitter.com/download/android" rel="nofollow">Twitter for Android</a>" +"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": {#225 ▶} +"geo": null +"coordinates": null +"place": null
上記の操作はララベルのアプリケーション内で行なっており、下記の記事を参考に
Laravel 5.5 で導入された Optional クラスについて
foreach ($timelines->statuses as $value) { //$timelines->statusesはレスポンスで返されるツイートの配列です。 if (optional(is_null($value->extended_entities))) { //インスタンスを作る } else { //インスタンスを作らない }
上記を試してみましたが、 $value->extended_entities
でアクセスする際に、
そもそもそのような、propertyにアクセスできないとのエラーが出てきました
Undefined property: stdClass::$extended_entities
どなたかアドバイスいただける方いますでしょうか?どうぞよろしくお願いいたしますm(_ _)m
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/13 00:58
2019/02/13 01:03
2019/02/13 01:42
2019/02/13 01:44
2019/02/13 01:50