简体   繁体   中英

PHP retweet syntax for twitter REST api v1.1 won't retweet from statuses/mentions_timeline array

I'm in the process of setting up a test bot for retweeting tweets from my user statuses/mentions_timeline. I really need some help with grabbing the status ID from the array of mentions the script creates, so that I can use the statuses/retweet/:id resource to then retweet mentions

Here's the code, I won't include the Auth Tokens but they are there and I have no problems posting status updates.

 $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); $twitter->host = "https://api.twitter.com/1.1/"; $tweets = $twitter->get('statuses/mentions_timeline', ['count' => 200]); $tweets1 = $twitter->get('users/show', ['count' => 170]); $totalTweets[] = $tweets; $page = 0; $twitter->host = "https://api.twitter.com/1.1/"; for($count = 20; $count < 21; $count += 20) { $max = count($totalTweets[$page]) - 1; $tweets = $twitter->get('statuses/mentions_timeline', ['count' => 20, 'max_id' => $totalTweets[$page][$max]->id_str, 'screen_name' => 'UnkindRTs', 'include_rts' => false]); $totalTweets[] = $tweets; $page += 1; } $twitter->host = "https://api.twitter.com/1.1/"; $start = 1; foreach($totalTweets as $page) { foreach($page as $key){ echo $start . ':' . $key->text . '<br>'; $postconn = $twitter->post('statuses/retweet/'.$key->text.id_str); $start++; } } 

figured it out thx for all the help though! XD

changed $postconn to

$postconn = $twitter->post('statuses/retweet/'.$key->id_str);

only had a small error xD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM