twitter api(php) - status / destroy - 什么都不返回

时间:2013-06-18 09:06:43

标签: php twitter

我正在使用tmOAuth库。

使用新的1.1 API,以下内容返回错误代码400 - 但身份验证已完成(对状态的身份验证工作相同)!我正在使用的库适用于所有调用,除了这个!

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

twitter API文档声明您不必在帖子中发送ID - 但这没有任何区别。

我今天用两个不同的库测试了这个,但都没有工作。

任何建议 - 有没有人知道它是否存在问题?

2 个答案:

答案 0 :(得分:1)

根据your comment,您已在两个库中针对 1.1 API 对此进行了测试。

你还没有在this one中测试过它。说明here,虽然您似乎已经拥有了您的凭据。

这基本上证明您使用的库存在问题,而不是twitter API。所以要么就github提交错误报告(他们还知道怎么做?),要么使用上面的其他库。

使用上述库所需的确切代码(并且有效,我只是测试了):

// 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);

答案 1 :(得分:0)

如果您正在使用Abraham Williams的twitteroauth php库并尝试删除旧的推文/转推,则需要构建post()查询:

$response = $connection->post('statuses/destroy/'.$tweetID, array()); //Curl url output = statuses/destroy/$tweetID.json