代码之家  ›  专栏  ›  技术社区  ›  Kristina

通过API获取YouTube视频的喜欢/不喜欢数量?

  •  11
  • Kristina  · 技术社区  · 16 年前

    我如何通过YouTube视频获得喜欢/不喜欢的数量 ?

    4 回复  |  直到 16 年前
        1
  •  11
  •   Andy    15 年前

    您可以这样查询YouTube API:

    <?php
    
    $curlhandle = curl_init();
    curl_setopt($curlhandle, CURLOPT_URL, "http://gdata.youtube.com/feeds/api/videos?v=2&alt=jsonc&q=computers&max-results=10&orderby=viewCount");
    curl_setopt($curlhandle, CURLOPT_RETURNTRANSFER, 1);
    
    $response = curl_exec($curlhandle);
    curl_close($curlhandle);
    
    $json = json_decode($response);
    
    
    foreach ($json->data->items as $result)
    {
    
            echo '<div class="video"><a href="'.$result->player->default.'" target="_blank">';
            echo '<img src="'.$result->thumbnail->hqDefault.'">';
            echo ' <div class="title"> '.$result->title.'</div><div class="rating">'.$result->likeCount.'</div></a></div>';
            //print_r($result);
    
    }
    

        2
  •  3
  •   Ash Catchem    14 年前

    YtRaing ytRating = videoEntry.getYtRating();
    int likes = ytRating.getNumLikes();
    int dislikes = ytRating.getNumDislikes();
    

    videoEntry,是来自(com.google.gdata网站.data.youtube.VideoEntry)

        3
  •  3
  •   tinkerr    14 年前

    如果您想知道不喜欢的东西在哪里,dislikeCount=ratingCount-likeCount

        4
  •  2
  •   josepainumkal    9 年前

    零件 作为

    下面是python代码:

    payload = {'id': search_result["id"]["videoId"], 'part': 'statistics', 'key': DEVELOPER_KEY}
    l = requests.Session().get('https://www.googleapis.com/youtube/v3/videos', params=payload)    
    print l.text
    

    {
     "kind": "youtube#videoListResponse",
     "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/0NR0uhQMzlaae_et8wHFZKsdFPA\"",
     "pageInfo": {
      "totalResults": 1,
      "resultsPerPage": 1
     },
     "items": [
      {
       "kind": "youtube#video",
       "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/vBL_50n3XI1eQcsdivfxN_g9c2M\"",
       "id": "hMncTg0iBko",
       "statistics": {
        "viewCount": "10281",
        "likeCount": "61",
        "dislikeCount": "9",
        "favoriteCount": "0",
        "commentCount": "1"
       }
      }
     ]
    }