twitter application API
hi currently am developing twitter update on my website...here i have written my code.. when im working in API console I COULD NOT GET APROPER RESULT..
<?php
$tweet_text = 'Hello Twitter';
print "Posting...\n";
$result = post_tweet($tweet_text);
print "Response code: " . $result . "\n";
function post_tweet($tweet_text) {
// Use Matt Harris' OAuth library to make the connection
// This lives at: https://github.com/themattharris/tmhOAuth
require_once('tmhoauth/tmhOAuth.php');
// Set the authorization values
// In keeping with the OAuth tradition of maximum confusion,
// the names of some of these values are different from the Twitter Dev interface
// user_token is called Access Token on the Dev site
// user_secret is called Access Token Secret on the Dev site
// The values here have asterisks to hide the true contents
// You need to use the actual values from Twitter
$connection = new tmhOAuth(array(
'consumer_key' => 'XXX',
'consumer_secret' => 'XXX',
'user_token' => 'XXX',
'user_secret' => 'XXX',
));
// Make the API call
$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));
return $connection->response['code'];
}
?>
stsuus response is look like below it
{
"request": "\/1\/statuses\/update.json",
"error": "Client must provide a 'status' parameter with a value."
}
statuus:403 forbidden
can 开发者_开发百科any one explain why error occured...
thanking you in advance
Actually, that is my code from my website, only the copyright info has been removed: http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/
The code you show here could not be the code you are running. Your code returns just the response code with this line: return $connection->response['code'];
But your message shows it returning the response as if your code was: return $connection->response['response'];
So you are not showing the real code you are running. That makes it hard to debug. The error you have can only return that message if there is no value for $tweet_text. I tested my code and when I used it with an empty version of $tweet_text, I got the same error message.
I then copied your code and put my OAuth tokens into it. It worked with no problem. I can only conclude that you are not showing us the code you are really running. It is impossible to tell you why it isn't working without seeing the actual code.
In the future when you find code with a GPL license, please leave the copyright and license statement in place.
精彩评论