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


Posting a direct message with Twitter API, PHP

这把我逼疯了!我正在尝试制作一个简单的推特应用程序。我已经尝试了一些在这里的老问题上看到的相关代码(也许代码已经过时了?)

我连接到twitter,使用凭据进行验证CCD_ 1,等等,并能够发布这样的推特:

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

大写文本是有效的twitter名称。这应该是一张简单的照片,但我正要把头发拔出来!如有任何帮助,我们将不胜感激!

谢谢,Eddie

您正在使用Abraham Williams的PHP OAuth Twitter库吗?我会推荐这个,而不是马特·哈里斯的。

发布推特:

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