2

I am using the tmOAuth library.

With the new 1.1 API, the following is returning an error code 400 - but authentication was done (same authentication for statuses works)! The library I am using works fine for all calls, except this one!

$tmhOAuth->request(
    'POST', $tmhOAuth->url('https://api.twitter.com/1.1/statuses/destroy/MYIDHERE.json'),
    array(
        'id' => MYIDHERE
    )
);

The twitter API documentation states that you don't have to send the id in post - but this doesn't make any difference.

I have tested this today with two different libraries, and neither work.

Any suggestions - does anyone know if there is an issue with it??

Jimbo
  • 25,790
  • 15
  • 86
  • 131

2 Answers2

3

According to your comment, you have tested this in two libraries for the 1.1 API.

You haven't tested it in this one though. Instructions here, although you seem to already have your credentials in hand.

This basically proves that the library you are using has the issue, not the twitter API. So either submit a bug report on github (how else are they to know?), or use another library like the one above.

The exact code required using the above library (and it works, I just tested it):

// Require the library file
require_once('TwitterAPIExchange.php');

// Set up your credentials
$settings = array(
    'oauth_access_token' => "YOUR_TOKEN",
    'oauth_access_token_secret' => "YOUR_TOKEN_SECRET",
    'consumer_key' => "YOUR_CONSUMER_KEY",
    'consumer_secret' => "YOUR_CONSUMER_SECRET"
);

// Put the correct ID in the URL
$url = 'https://api.twitter.com/1.1/statuses/destroy/YOURIDHERE.json';

// Set the request type
$requestMethod = 'POST';

// Set the post fields
$postfields = array('id' => 'YOURIDHERE');

// Make the request
$twitter = new TwitterAPIExchange($settings);
$json =  $twitter->buildOauth($url, $requestMethod)
                 ->setPostfields($postfields)
                 ->performRequest();

// Dump the response
$result = json_decode($json);
var_dump($result);
Community
  • 1
  • 1
Jimbo
  • 25,790
  • 15
  • 86
  • 131
0

If you're using the twitteroauth php library from Abraham Williams and trying to delete old tweets/retweets you need to construct the post() query as such:

$response = $connection->post('statuses/destroy/'.$tweetID, array()); //Curl url output = statuses/destroy/$tweetID.json
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156