i have been doing some integration with twitter using php and this api: https://github.com/abraham/twitteroauth
I’ve managed to tweet, but im having some difficulties in understand and evaluate the return values.
For instance in the file callback.php if i want to post a tweeter i have this code:
$result = $connection->post(
'statuses/update',
array(
'status' => 'Tweet teste de API!',
));
but how do i know what $result is returning me? i’ve tried to echo it and for it but it doesnt seem to work, any insights on that? I want to be able to see all the returning keys available.
I’ve tried this:
foreach ($result as $key => $value) {
echo "$key, $value <br />";
}
but it only prints two keys then a error appers that i cant convert stdclass. Any insight on how to see this or better api documentation?
Thank you
When posting with
statuses/update, the returned$resultwill be a PHP class/object containing the created tweet, structured the same asstatus/show:id.It looks like http://dev.twitter.com/doc/post/statuses/update fails to mention that the created tweet will be returned upon success. But if you read the bottom of http://dev.twitter.com/doc/get/statuses/show/:id, you can see all the different data you can access from
$result.You should also be able to see the object’s entirety with
var_dump($result).This example should hopefully work for you; it posts the tweet, then echos the created tweet’s text and the user’s screen name:
Similarly, pretty much any Twitter resource found on http://dev.twitter.com/doc can be accessed with
$result = $connection->post().Just have the 1st parameter be a string of the desired resource (eg
statuses/updateorusers/show), and the 2nd parameter be an array of the resource’s parameters, then you can access whatever the resource returns with$result.The Twitter API is at your fingertips, and abraham’s twitteroauth library makes it easy 🙂