Reputation: 19159
I'm currently able to get the like and dislike count of a video using YouTube Data API v3. You can do a live demo with this tool and filling the following fields:
The response is:
{
"kind": "youtube#videoListResponse",
"etag": "\"3bd49bOmAIO-xOEBT1-7BG40uHA/fpwF_APn7OSQWrMW_YeQrmSElIg\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "\"3bd49bOmAIO-xOEBT1-7BG40uHA/ooZFGbFJOoCCq_lbYsU4p0T75lA\"",
"id": "pPRWdhPanDg",
"statistics": {
"viewCount": "250",
"likeCount": "0", // There you have it
"dislikeCount": "0", // There you have it
"favoriteCount": "0",
"commentCount": "75"
}
}
]
}
The data is correct, there are no ratings for that video. But the question is, how can I know that the ratings for that video are actually disabled? I must differentiate the case where there are no ratings and the one in which they are disabled so it's just impossible for users to rate.
Upvotes: 0
Views: 682
Reputation: 13667
AFAIK, the capability to get this information is not yet returned through the v3 API yet, although I believe it's on their roadmap to make it so. For now, the only way to do this reliably would be to either:
A) Make an attempt to rate the video with the video->rate endpoint ... if rating is allowable, it will return a 200 request (in which case you'd then have to do another call to remove the rating), and if rating is disabled it returns a 403 with the error "VideoRatingDisabled" as the response body. Note that this is likely an undesirable solution because it requires two extra calls AND requires that you make the request authorized with an oAuth token (i.e. you'd have to have users log in first).
B) Use a v2 API call until the info is ported to v3 services. The feed you want is https://gdata.youtube.com/feeds/api/videos/PRWdhPanDg?v=2.1&alt=jsonc -- look for the data.accessControl.rate parameter to be set to allowed
Upvotes: 2