Reputation: 51
This is driving me up the wall! I'm trying to make a simple little Twitter app. I've tried a some of the relavent code seen on older question here (maybe the code is out of date?)
I make the connection to twitter, validate with credentials using
$connection = new tmhOAuth(array('consumer_key' =>
,
etc and able to post a tweet like this:
$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));
but when I try to do a direct message, the PHP script seems to hang at this spot:
I've tried it this way:
$connection->post('1/direct_messages/new', array('text' => 'dm text here', 'FROM_TWITTER_NAME' => 'TO_TWITTER_NAME'));
I've also tried this:
$method = 'direct_messages/new';
$receiverScrName = "SCREEN_NAME";
$parameters = array('screen_name' => $receiverScrName, 'text' => 'how are you');
$connection->post($method, $parameters);
The upper case text is valid twitter names. this should be the picture of simplicity and yet I'm about to pull my hair out! Any help would be greatly appreciated!
Thanks, Eddie
Upvotes: 2
Views: 4191
Reputation: 543
Are you using Abraham Williams' PHP OAuth Twitter library? I'd recommend that over Matt Harris'.
To post a tweet:
$tweet = "This is my tweet";
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
$connection->post('statuses/update', array('status' => $tweet));
To post a direct message:
$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));
Upvotes: 2