Hi all. I've been teaching myself PHP in order to make a personal (not selling) retweet cron job.
I am using Abrahams twitteroauth library and keys/tokens I generated.
I am having no problem retrieving a list of recent tweets from the donor account and no problem going through that list, ignoring retweets and replies.
What I'm stuck on is this:
How do I cycle through a list of several accounts (store in a CSV file) and retweet a given tweetID?
Does each account need its own keys/codes or can I use one twitter app for this?
Why is there so little good documentation on the twitter api and php for posting retweets?
Thanks - current code below
EQP
I am using Abrahams twitteroauth library and keys/tokens I generated.
I am having no problem retrieving a list of recent tweets from the donor account and no problem going through that list, ignoring retweets and replies.
What I'm stuck on is this:
How do I cycle through a list of several accounts (store in a CSV file) and retweet a given tweetID?
Does each account need its own keys/codes or can I use one twitter app for this?
Why is there so little good documentation on the twitter api and php for posting retweets?
Thanks - current code below
EQP
PHP:
<?php
date_default_timezone_set('America/New_York');
session_start();
require_once("twitteroauth.php"); //Path to twitteroauth library
$twitteruser = "CPlusPainter";
$notweets = 10;
$consumerkey = "xxxxxxxxxxxxxxxxxx";
$consumersecret = "xxxxxxxxxxxxxxxxxxx";
$accesstoken = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
$accesstokensecret = "xxxxxxxxxxxxxxxxxxxxxxxx";
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
$connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
return $connection;
}
$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);
$tweetData = json_decode(json_encode($tweets), true);
foreach ($tweetData as $tweet) {
echo '<br/>ID: ' . $tweet['id_str'];
echo '<br/>Tweet: ' . $tweet['text'];
$retweet = $tweet['retweeted_status'] != NULL ? TRUE : false;
$reply = $tweet['in_reply_to_status_id'] != NULL ? TRUE : false;
echo "<br/>reply " . $reply;
echo "<br/>retweet " . $retweet;
echo "</p>";
}
?>