使用Twitter API,PHP发布直接消息

时间:2012-09-02 10:36:11

标签: php twitter

这让我起了墙!我正在尝试制作一个简单的小Twitter应用程序。我已经尝试了一些在旧问题上看到的相关代码(也许代码已经过时了?)

我建立了与twitter的连接,使用凭据进行验证     $connection = new tmhOAuth(array('consumer_key' =>, 等,并能够发布这样的推文:

$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));

但是当我尝试做直接消息时,PHP脚本似乎挂在这个位置:

我试过这种方式:

$connection->post('1/direct_messages/new', array('text' => 'dm text here', 'FROM_TWITTER_NAME' => 'TO_TWITTER_NAME'));

我也试过这个:

$method = 'direct_messages/new';
$receiverScrName = "SCREEN_NAME";
$parameters = array('screen_name' => $receiverScrName, 'text' => 'how are you');
$connection->post($method, $parameters);

大写文本是有效的推特名称。 这应该是简单的图片,但我要把我的头发拉出来!任何帮助将不胜感激!

谢谢, 埃迪

1 个答案:

答案 0 :(得分:2)

您使用的是Abraham Williams的PHP OAuth Twitter库吗?我建议过Matt Harris'。

发布推文:

$tweet = "This is my tweet"; 

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
$connection->post('statuses/update', array('status' => $tweet));

发布直接留言:

$msg = "This is my direct message"; 

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
$connection->post('direct_messages/new', array('user_id' => $user->id, 'text' => $msg));