Get title from YouTube videos

前端 未结 17 1822
抹茶落季
抹茶落季 2020-12-07 17:30

I want to extract the Title of YouTube\'s videos. How can I do this?

Thanks.

17条回答
  •  时光说笑
    2020-12-07 17:38

    I'll lay out the process as outlined by the YouTube API v3 documentation.

    1. Make a / login to the Google account that you want to be associated with your YouTube API use.
    2. Create a new project at https://console.developers.google.com/apis/credentials.

      • On the upper left, next to the Google APIs logo, go to Select a project and Create project +.
      • Wait a moment for the creation to finish.
    3. Make a new API key. You'll need it to access video info under v3.

      • If you're not already there, go to Credentials under the navigator on the left hand side, APIs and Services > Credentials.
      • Under the Credentials tab, click Create Credentials and select API key.
      • Copy the API key to your clipboard.
    4. Providing a video ID and your newly created API key, go to this link to see your work in action: https://www.googleapis.com/youtube/v3/videos?id=&key=%20&part=snippet (no angle brackets)
      • For more info on what you can access, see here: https://developers.google.com/youtube/v3/getting-started#partial. For convenience, I'll copy one of their examples here (Example 4). The fields and part parameters in the URL are key here.

    Example

    The URL is, well, what URL you can go to through your browser to check it out. In return, you should get what's under API response:.

    URL: https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY
         &fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics
    
    Description: This example modifies the fields parameter from example 3
                 so that in the API response, each video resource's snippet
                 object only includes the channelId, title,
                 and categoryId properties.
    
    API response:
    
    {
     "videos": [
      {
       "id": "7lCDEYXw3mM",
       "snippet": {
        "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
        "title": "Google I/O 101: Q&A On Using Google APIs",
        "categoryId": "28"
       },
       "statistics": {
        "viewCount": "3057",
        "likeCount": "25",
        "dislikeCount": "0",
        "favoriteCount": "17",
        "commentCount": "12"
       }
      }
     ]
    }
    

    This gives you video info in the .json file format. If your project is to access this info through JavaScript, you may be going here next: How to get JSON from URL in Javascript?.

提交回复
热议问题