I couldn't find 开发者_JAVA百科how to do this through the API documentation.
There is an undocumented way to get this information if you're authenticated.
https://api.twitter.com/i/statuses/[tweet.id]/activity/summary.json
An even larger list of API endpoints that are undocumented can be found in the Ruby Twitter library https://github.com/sferik/twitter/blob/master/lib/twitter/client.rb
The New API V1.1 Now supports the tweet favorite's count. Here try it out
stdClass Object
(
[created_at] => Thu Apr 04 20:09:16 +0000 2013
[id] => 319904523520983041
[id_str] => 319904523520983041
[text] => North Koreas perspective of the world in the next 5 years http://t.co/MxRgD00VCY
[source] => web
[truncated] =>
[in_reply_to_status_id] =>
[in_reply_to_status_id_str] =>
[in_reply_to_user_id] =>
[in_reply_to_user_id_str] =>
[in_reply_to_screen_name] =>
[geo] =>
[coordinates] =>
[place] =>
[contributors] =>
[retweet_count] => 7
[favorite_count] => 7
[entities] => stdClass Object
(
[hashtags] => Array
Upgrade and start Using it.
It is now possible to do this via the statuses/show/:id endpoint. (It requires authentication.)
Example:
GET https://api.twitter.com/1.1/statuses/show.json?id=210462857140252672
or
GET https://api.twitter.com/1.1/statuses/show/210462857140252672.json
The returned JSON will have a favorite count member.
Note that while the example response in the linked documentation says "favourites_count"
, the actual returned JSON property is called "favorite_count"
.
Edit: I've just noticed that the documented "favourites_count"
property is inside the user
member of the response (it tells you how many tweets have the user favorited in total). The "favorite_count"
property, which tells you how many times the tweet was favorited, is in the root of the returned JSON object, and it seems like it's undocumented.
(This endpoint also returns retweet_count
and much more.)
Sorry, there's no official way to get this at the present time. All you can tell is if the tweet has been favorited by the authenticated user. There is a favorites_count
in the object graph, however this applies to the user that tweeted the tweet, not the tweet itself.
EDIT: Jun. 19, '12 - See mmrobins's answer for links to some of Twitter's undocumented API methods. As always, be careful when using undocumented endpoints since they can change without notice.
The official answer to your question is here https://dev.twitter.com/docs/faq#6898. It suggests to count them real time as the functionality is not supported
As workaround we can scrap page with tweet https://twitter.com/USERNAME/status/TWEET_ID
and use this regex to extract favorited count
(?<=^|>)[^><]+?(?=</strong> Favorites|$)
or use deprecated api
http://api.twitter.com/1/statuses/show/308910231910490112.json
official doc says
How do I count favorites?
The number of times a tweet was favorited is now available as part of tweet objects in the REST, Streaming, and Search APIs -- you'll find it presented in the "favorite_count" field.
Additionally, User streams and Site streams both stream events when an authenticated user favorites tweets or has their tweets favorited. Using these authenticated streaming APIs, you can count favorites in real-time as they happen.
But please note, that
Site Streams is currently in a limited beta. Access is restricted to whitelisted accounts.
And sorry for emotions, but it's in beta more than two years.
So you cannot..
精彩评论