2011-08-03 9 views
1

私はtmhOAuth.php/classを使ってtwitterにログインしています。私はログインしてツイートを送るのに成功しています。Twitter API(THM oauth)からJSONデータを解読する際の問題

friends.phpスクリプトを使用すると、データベースに挿入するときに問題が発生します。私は、私の問題はコードの$ページング変数のどこかにあると信じています。それは7回だけループしているからです。私は626人をフォローしていますので、私の$ idsは626、ページングは​​7です。

私はWebブラウザでphpを実行すると、7人のフォロワーしか抽出できません。ユーザ526、ユーザ426に続く...)各ページリクエストで最後のユーザをエコーし​​ているようです。これは、PAGESIZE定数を使用して、一度に100ユーザーIDを要求することが一部原因です。 $ 626などの異なる番号で$ページングを調整すると、{"エラー":{{"code":17、 "メッセージ": "指定された用語に一致するユーザーがありません"}}}

残念ながら、私はこれがかなり単純なPHPのループの問題だと思うが、私はもはやまっすぐ考えることができますこれをクラックしようと費やした時間の後。

ありがとうございます。

define('PAGESIZE', 100); 
require 'tmhOAuth.php'; 
require 'tmhUtilities.php'; 

if ($tmhOAuth->response['code'] == 200) { 
$data = json_decode($tmhOAuth->response['response'], true); 
$ids += $data['ids']; 
$cursor = $data['next_cursor_str']; 
} else { 
echo $tmhOAuth->response['response']; 
break; 
} 
endwhile; 

// lookup users 
$paging = ceil(count($ids)/PAGESIZE); 
$users = array(); 
for ($i=0; $i < $paging ; $i++) { 
$set = array_slice($ids, $i*PAGESIZE, PAGESIZE); 
$tmhOAuth->request('GET', $tmhOAuth->url('1/users/lookup'), array(
'user_id' => implode(',', $set) 
)); 

// check the rate limit 
check_rate_limit($tmhOAuth->response); 

if ($tmhOAuth->response['code'] == 200) { 
$data = json_decode($tmhOAuth->response['response'], true); 
if ($tmhOAuth->response['code'] == 200) { 
$data = json_decode($tmhOAuth->response['response'], true); 
$name = array(); 
foreach ($data as $val) 
    { 
     $name = $data[0]['screen_name']; 
    } 
    echo "this is the screen name " .$name. "\n"; 
    $users += $data; 
} else { 
echo $tmhOAuth->response['response']; 
break; 
} 

} 
var_dump($users); 
?> 

私はエコーしようとしていたデータは、その後、解析し、データベースに挿入するには、標準のTwitterのJSONデータであるので、私はメッセージでこれを含まれません。すべてのヘルプは

答えて

0

問題が解決次のようになります。

foreach ($data as $val) 
{ 
    $name = $val['screen_name']; 
    echo "this is the screen name " .$name. "\n"; 
    $users[] = $name; 
} 
関連する問題