我试图通过人员列表重新发布一条推文。
人员列表在我的数据库中。这是我的疑问:
$query = mysql_query("SELECT * FROM users");
while($row = mysql_fetch_assoc($query)){
$users[] = $row;
}
我试图通过foreach循环遍历此列表。问题是只有名单上的第一个人重新推文。对于其他人,它给出了一个错误说:
stdClass Object ( [message] => Invalid or expired token [code] => 89 )
至于我的foreach循环:
foreach($users as $value){
$oauth_token = $value['oauth_token'];
$oauth_secret = $value['oauth_secret'];
$twitteroauth = new TwitterOAuth('****', '****', $oauth_token, $oauth_secret);
$result = $twitteroauth->post('statuses/retweet/'.$tweet_id);
}
这是第一次循环的结果:
stdClass Object ( [in_reply_to_status_id] => [user] => stdClass Object ( [name] => hamid [profile_background_color] => C0DEED [lang] => en [screen_name] => rumble909 [id] => 261675207 [profile_background_image_url] => http://a0.twimg.com/images/themes/theme1/bg.png [verified] => [default_profile] => 1 [notifications] => [profile_link_color] => 0084B4 [profile_image_url_https] => https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_3_normal.png [statuses_count] => 14 [contributors_enabled] => [id_str] => 261675207 [profile_use_background_image] => 1 [following] => [utc_offset] => [profile_text_color] => 333333 [created_at] => Sun Mar 06 13:04:44 +0000 2011 [listed_count] => 0 [profile_image_url] => http://a0.twimg.com/sticky/default_profile_images/default_profile_3_normal.png [profile_background_image_url_https] => https://twimg0-a.akamaihd.net/images/themes/theme1/bg.png [time_zone] => [follow_request_sent] => [protected] => [profile_sidebar_border_color] => C0DEED [description] => [friends_count] => 5 [followers_count] => 2 [profile_background_tile] => [default_profile_image] => 1 [profile_sidebar_fill_color] => DDEEF6 [url] => [entities] => stdClass Object ( [description] => stdClass Object ( [urls] => Array ( ) ) ) [favourites_count] => 0 [is_translator] => [geo_enabled] => [location] => ) [in_reply_to_screen_name] => [id_str] => 349183887999635456 [retweeted_status] => stdClass Object ( [in_reply_to_status_id] => [user] => stdClass Object ( [name] => TwtrAlert [profile_background_color] => C0DEED [lang] => nl [screen_name] => TwtrAlert [id] => 1468194638 [profile_background_image_url] => http://a0.twimg.com/images/themes/theme1/bg.png [verified] => [default_profile] => 1 [notifications] => [profile_link_color] => 0084B4 [profile_image_url_https] => https://twimg0-a.akamaihd.net/profile_images/3758330661/9c75fdc8679415b11d570a92534339a5_normal.png [statuses_count] => 14 [contributors_enabled] => [id_str] => 1468194638 [profile_use_background_image] => 1 [following] => [utc_offset] => [profile_text_color] => 333333 [created_at] => Wed May 29 20:29:45 +0000 2013 [listed_count] => 0 [profile_image_url] => http://a0.twimg.com/profile_images/3758330661/9c75fdc8679415b11d570a92534339a5_normal.png [profile_background_image_url_https] => https://twimg0-a.akamaihd.net/images/themes/theme1/bg.png [time_zone] => [follow_request_sent] => [protected] => [profile_sidebar_border_color] => C0DEED [description] => Doneer 10 Tweets per jaar voor de belangrijkste meldingen van Nederland. Meld je nu aan door in te loggen op: #Amberalert [friends_count] => 0 [followers_count] => 0 [profile_background_tile] => [default_profile_image] => [profile_sidebar_fill_color] => DDEEF6 [url] => [entities] => stdClass Object ( [description] => stdClass Object ( [urls] => Array ( ) ) ) [favourites_count] => 0 [is_translator] => [geo_enabled] => [location] => ) [in_reply_to_screen_name] => [id_str] => 349183884652580864 [contributors] => [geo] => [created_at] => Mon Jun 24 15:15:00 +0000 2013 [favorited] => [truncated] => [source] => Nessesis [entities] => stdClass Object ( [user_mentions] => Array ( ) [urls] => Array ( ) [hashtags] => Array ( ) ) [place] => [id] => 3.4918388465258E+17 [in_reply_to_status_id_str] => [coordinates] => [in_reply_to_user_id] => [retweet_count] => 1 [in_reply_to_user_id_str] => [text] => .... [retweeted] => 1 ) [contributors] => [geo] => [created_at] => Mon Jun 24 15:15:01 +0000 2013 [favorited] => [truncated] => [source] => Nessesis [entities] => stdClass Object ( [user_mentions] => Array ( [0] => stdClass Object ( [id_str] => 1468194638 [id] => 1468194638 [screen_name] => TwtrAlert [indices] => Array ( [0] => 3 [1] => 13 ) [name] => TwtrAlert ) ) [hashtags] => Array ( ) [urls] => Array ( ) ) [place] => [id] => 3.4918388799964E+17 [in_reply_to_status_id_str] => [coordinates] => [in_reply_to_user_id] => [retweet_count] => 1 [in_reply_to_user_id_str] => [text] => RT @TwtrAlert: .... [retweeted] => 1 )
以及上述错误后的那些:
stdClass Object ( [message] => Invalid or expired token [code] => 89 )
有人请告诉我我的代码有什么问题,因为我无法分辨。
提前致谢。
编辑:
TwitterOauth似乎在第一个和第二个之间有所不同。
首次循环:
TwitterOAuth Object ( [http_code] => 200 [url] => https://api.twitter.com/1.1/statuses/retweet/352047945522229248.json [host] => https://api.twitter.com/1.1/ [timeout] => 30 [connecttimeout] => 30 [ssl_verifypeer] => [format] => json [decode_json] => 1 [http_info] => Array ( [url] => https://api.twitter.com/1.1/statuses/retweet/352047945522229248.json [content_type] => application/json; charset=utf-8 [http_code] => 200 [header_size] => 1339 [request_size] => 481 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.979719 [namelookup_time] => 3.4E-5 [connect_time] => 0.099769 [pretransfer_time] => 0.307282 [size_upload] => 273 [size_download] => 3919 [speed_download] => 4000 [speed_upload] => 278 [download_content_length] => 3919 [upload_content_length] => 0 [starttransfer_time] => 0.979687 [redirect_time] => 0 [certinfo] => Array ( ) ) [useragent] => TwitterOAuth v0.2.0-beta2 [sha1_method] => OAuthSignatureMethod_HMAC_SHA1 Object ( ) [consumer] => OAuthConsumer Object ( [key] => ***** [secret] => ***** [callback_url] => ) [token] => OAuthConsumer Object ( [key] => 261675207-coNLDFjVXfbN9LLUnlcBAEt2fQAgf8d98iKGqHkT [secret] => YRiSvCkPDXf8S59Pv2AUkoGxUq5VGGxJGQz2PGlVSo [callback_url] => ) [http_header] => Array ( [cache_control] => no-cache, no-store, must-revalidate, pre-check=0, post-check=0 [content_length] => 3919 [content_type] => application/json; charset=utf-8 [date] => Tue, 02 Jul 2013 12:55:46 GMT [etag] => "2419a11ea1bf2086f5084b7b09da6c52" [expires] => Tue, 31 Mar 1981 05:00:00 GMT [last_modified] => Tue, 02 Jul 2013 12:55:46 GMT [pragma] => no-cache [server] => tfe [set_cookie] => guest_id=v1%3A137276974644131212; Domain=.twitter.com; Path=/; Expires=Thu, 02-Jul-2015 12:55:47 UTC [status] => 200 OK [strict_transport_security] => max-age=631138519 [vary] => Accept-Encoding [x_access_level] => read-write [x_frame_options] => SAMEORIGIN [x_mid] => 1df98af5f5d625dc987acc730e6e3f3985f451e0 [x_runtime] => 0.38122 [x_transaction] => 04aac3ca1caa40b3 [x_transaction_mask] => a6183ffa5f8ca943ff1b53b5644ef114d41f4c7d ) )
第二次循环:
TwitterOAuth Object ( [http_code] => 401 [url] => https://api.twitter.com/1.1/statuses/retweet/352047945522229248.json [host] => https://api.twitter.com/1.1/ [timeout] => 30 [connecttimeout] => 30 [ssl_verifypeer] => [format] => json [decode_json] => 1 [http_info] => Array ( [url] => https://api.twitter.com/1.1/statuses/retweet/352047945522229248.json [content_type] => application/json; charset=utf-8 [http_code] => 401 [header_size] => 306 [request_size] => 481 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.417521 [namelookup_time] => 3.6E-5 [connect_time] => 0.099975 [pretransfer_time] => 0.309829 [size_upload] => 273 [size_download] => 61 [speed_download] => 146 [speed_upload] => 653 [download_content_length] => 61 [upload_content_length] => 0 [starttransfer_time] => 0.417509 [redirect_time] => 0 [certinfo] => Array ( ) ) [useragent] => TwitterOAuth v0.2.0-beta2 [sha1_method] => OAuthSignatureMethod_HMAC_SHA1 Object ( ) [consumer] => OAuthConsumer Object ( [key] => ****** [secret] => ***** [callback_url] => ) [token] => OAuthConsumer Object ( [key] => 1218650107-KPo4mx9rRwHcfXIqYXF3NyUy7ZUfLzufyplPabQ [secret] => L0zsMdR4Q1zQsB5VyGLhNf990F9ENgn2ddsjXADLI [callback_url] => ) [http_header] => Array ( [content_length] => 61 [content_type] => application/json; charset=utf-8 [date] => Tue, 02 Jul 2013 12:55:47 UTC [server] => tfe [set_cookie] => guest_id=v1%3A137276974742435806; Domain=.twitter.com; Path=/; Expires=Thu, 02-Jul-2015 12:55:47 UTC [strict_transport_security] => max-age=631138519 ) )