Saturday, 28 September 2013

How to make a PHP Twitter API 1.1 delete tweet tool faster?

How to make a PHP Twitter API 1.1 delete tweet tool faster?

Hello :) I have been trying out ways to make my Tweet delete script faster
at deleting Tweets. I've tried using foreach and while loops, to loop
through an array of Tweet IDs and POST them to the Twitter API, but this
only deletes one Tweet every 2 seconds, roughly, and this speed does not
increase even if I cache the Tweet IDs beforehand using a text file or
MySQL.
The Twitter API requires that only one Tweet ID at a time is POSTed, and
the API returns a summary of all the Tweets that were deleted once the
POST process has completed.
How can I use PHP to send multiple single requests at the same time to the
API for faster deletion, instead of sending one Tweet ID at a time? The
Twitter API library I am using, uses cURL. Here is the deletion script
using a foreach loop.
$url =
'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = "?screen_name=" . $myscreenname . "&count=200";
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$results = json_decode($response, true);
foreach ($results as $arrSearchResult)
{
$post['id'] = $arrSearchResult['id_str'];
$url = "https://api.twitter.com/1.1/statuses/destroy/%s.json";
$postfields = array
(
"id" => null,
"trim_user" => true
);
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->buildOauth(sprintf($url,
$arrSearchResult['id_str']), "POST")
->setPostfields($postfields)
->performRequest();
}

No comments:

Post a Comment