2016-09-13 11 views
1

私はPHPでTwitter APIを使用するためのいくつかのテストを行っています。PHPを使用してTwitterで検索を実行し、結果を出力しようとしています

はぐちゃぐちゃの「ロット」の後、私は最初に私はすべての情報を読み取ることができ、それが働いて...私はネストされた配列との問題を抱えていますが

のようなものを持っているが、その後、私は後にあったものを実現します配列内の配列

私はPHPの専門家ではないことを指摘しておきます。私はPHPの専門家ではなく、物事を引き離してカスタマイズできる人物です。以下で完了しました。

<?php 

require_once('TwitterAPIExchange.php'); 
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/ 
$settings = array(
    'oauth_access_token' => "SECRET", 
    'oauth_access_token_secret' => "SECRET", 
    'consumer_key' => "SECRET", 
    'consumer_secret' => "SECRET" 
); 
$url = 'https://api.twitter.com/1.1/search/tweets.json'; 


$requestMethod = "GET"; 
$getfield = '?q=%22anyone%20recommend%22&result_type=recent'; 

$twitter = new TwitterAPIExchange($settings); 
$string = json_decode($twitter->setGetfield($getfield) 
->buildOauth($url, $requestMethod) 
->performRequest(),$assoc = TRUE); 
if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>".$string[errors][0]["message"]."</em></p>";exit();} 

foreach($string as $items) 
    { 
    foreach ($items as $value){ 

     echo "Time and Date of Tweet: ".$value['created_at']."<br />"; 
     echo "Tweet: ". $value['text']."<br />"; 
     echo "Tweeted by: ". $value['user']['name']."<br />"; 
     echo "Screen name: ". $value['user']['screen_name']."<br />"; 
     echo "Followers: ". $value['user']['followers_count']."<br />"; 
     echo "Friends: ". $value['user']['friends_count']."<br />"; 
     echo "Listed: ". $value['user']['listed_count']."<br /><hr />"; 

     } 
    } 

?> 

これは、最大最後の3つのまたは4応答するまで、右である、私は戻って得るものです:

Time and Date of Tweet: Tue Sep 13 14:27:00 +0000 2016 
Tweet: Can anyone recommend a good thing to have 
Tweeted by: jmprcx 
Screen name: jmprcx 
Followers: 1194 
Friends: 5 
Listed: 2 
Time and Date of Tweet: Tue Sep 13 14:25:49 +0000 2016 
Tweet: RT @SunSparklesBlog: 1/? Really want to have a new layout for my blog. I have some ideas what I want, can anyone recommend a blog design co… 
Tweeted by: SpainScope 
Screen name: SpainScope 
Followers: 8060 
Friends: 7129 
Listed: 2436 
Time and Date of Tweet: Tue Sep 13 14:25:17 +0000 2016 
Tweet: #bbloggers Can anyone recommend a nail treatment for weak nails after gel/acryilics please? Not OPI nail envy as that didn't work for me 🙂 
Tweeted by: Zoë 
Screen name: MammafulZo 
Followers: 3080 
Friends: 309 
Listed: 103 
Time and Date of Tweet: Tue Sep 13 14:24:44 +0000 2016 
Tweet: Can anyone recommend a good setting spray? I'm going to a wedding this weekend and I need my makeup to last lol 
Tweeted by: Kayla✨ 
Screen name: xdeadweightx_ 
Followers: 948 
Friends: 1392 
Listed: 1 
Time and Date of Tweet: Tue Sep 13 14:23:27 +0000 2016 
Tweet: RT @Merlinho_: Can anyone recommend a #book or book series for 7-8 year old girls please? RT appreciated. Thanks X 
Tweeted by: Del The Chauffeur 
Screen name: DJWalker11 
Followers: 2323 
Friends: 2303 
Listed: 77 
Time and Date of Tweet: Tue Sep 13 14:22:36 +0000 2016 
Tweet: RT @Merlinho_: Can anyone recommend a #book or book series for 7-8 year old girls please? RT appreciated. Thanks X 
Tweeted by: Del 
Screen name: DE180Y 
Followers: 806 
Friends: 361 
Listed: 22 
Time and Date of Tweet: Tue Sep 13 14:22:31 +0000 2016 
Tweet: Tomorrow I shall be exploring Jesmond, Newcastle for good coffee shops/health restaurants. Can anyone recommend? #NEBlogger #NEFollowers 
Tweeted by: Ellie Travis 
Screen name: Perf_STherapy 
Followers: 764 
Friends: 2173 
Listed: 41 
Time and Date of Tweet: Tue Sep 13 14:21:58 +0000 2016 
Tweet: RT @Merlinho_: Can anyone recommend a #book or book series for 7-8 year old girls please? RT appreciated. Thanks X 
Tweeted by: BuxtonGooner 
Screen name: buxtongooner 
Followers: 2783 
Friends: 805 
Listed: 78 
Time and Date of Tweet: Tue Sep 13 14:21:18 +0000 2016 
Tweet: can anyone recommend co-working spaces in San Diego? or does anyone have an extra desk at their office that I can pull up to? 
Tweeted by: Andrew M. Galvan 
Screen name: andrewmgalvan 
Followers: 913 
Friends: 1214 
Listed: 16 
Time and Date of Tweet: Tue Sep 13 14:21:02 +0000 2016 
Tweet: My belly is expanding and I can't fit into my jeans anymore 󾌡 Can anyone recommend somewhere I can get maternity... 
Tweeted by: Kristen O'Gorman 
Screen name: KOGaroo 
Followers: 315 
Friends: 778 
Listed: 9 
Time and Date of Tweet: Tue Sep 13 14:20:19 +0000 2016 
Tweet: RT @Merlinho_: Can anyone recommend a #book or book series for 7-8 year old girls please? RT appreciated. Thanks X 
Tweeted by: Nick Davison 
Screen name: njd10happy 
Followers: 3156 
Friends: 3044 
Listed: 40 
Time and Date of Tweet: Tue Sep 13 14:19:37 +0000 2016 
Tweet: Can anyone recommend a #book or book series for 7-8 year old girls please? RT appreciated. Thanks X 
Tweeted by: Merlinho 
Screen name: Merlinho_ 
Followers: 1842 
Friends: 811 
Listed: 43 
Time and Date of Tweet: Tue Sep 13 14:19:29 +0000 2016 
Tweet: can anyone recommend me any Graphics Tablets? dunno what ones to get 
Tweeted by: jodinski 
Screen name: JoDinski 
Followers: 2788 
Friends: 325 
Listed: 17 
Time and Date of Tweet: Tue Sep 13 14:19:05 +0000 2016 
Tweet: SAGINAW PEOPLE HELP ME OUT!!!!! Can anyone recommend a good daycare center here in the area. Preferably a... 
Tweeted by: Daniel A.A. Ishmel 
Screen name: DanielsAMG2016 
Followers: 49 
Friends: 223 
Listed: 0 
Time and Date of Tweet: Tue Sep 13 14:17:01 +0000 2016 
Tweet: Can anyone recommend a nice tinted moisturiser or bb cream i cannot deal with foundation anymore and my complexion is shite x 
Tweeted by: Shannon 
Screen name: watsonehtelly 
Followers: 377 
Friends: 284 
Listed: 2 
Time and Date of Tweet: 
Tweet: 
Tweeted by: 
Screen name: 
Followers: 
Friends: 
Listed: 
Time and Date of Tweet: 
Tweet: 
Tweeted by: 
Screen name: 
Followers: 
Friends: 
Listed: 
Time and Date of Tweet: 7 
Tweet: 7 

Fatal error: Cannot use string offset as an array in 

/home/public_html/bots/twitter3.php on line 31 

お知らせ応答の最後のカップルが空白であるか、エラー。 https://github.com/J7mbo/twitter-api-php

を、私は、このガイドを従っていました:

私はここからTwitterAPIExchange.phpを使用していますhttp://iag.me/socialmedia/build-your-first-twitter-app-using-php-in-8-easy-steps/

は、誰かが私が間違っている私を見ることができますか?

答えて

0

明らかに、$ value ['created_at']がもう存在しないところにいるようです。状況を分析するには、このように$文字列の内容を検討する必要があります:あなたが画面上でこの変数ダンプを取得したら

echo "\n<p>DEBUG: string = <pre>" . print_r($string) . "</pre>"; 

あなたは$値が「created_atと」キーを持たない理由を見つけることができると修正しますそれ。

関連する問題