since YouTube Data API v2 no longer exists, you need extra permission from the user to read video comments (like permission youtube.force-ssl). There isn't any possibility to read video comments with the permission "youtube.readonly".
With Data API v2 ist was possible to read youtube video comments like this:
https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments
But how is it possible to get the youtube comments only with "youtube.readonly" permission? YouTube loads comments dynamically with ajax, so is it possible to crawl these comments?
Thanks a lot!
If you want to read top level comment by url, like you have said in your question
You can get it, but you need a youtube api key,(its free)
https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId=NK94g7Qctuw&key={YOUR_API_KEY}
You do not have to get any access token, again if you want it to get from access token try to get refresh token like
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
Add above two line code in youtube api sample, you will get a auto refresh token. Hope it helps you.
Related
I used YouTube Data API a bit. My page does display users input from Google's servers eg video title. Would you be able to get an XSS by putting to code on Youtube and calling in back on my domain.
YouTube does not allow tags to be created so XSS over an API is no worry.
Sorry don't uses YouTube upload that much
I need to use youtube username in a javascript script that retrieves data from youtube API with username
the problem is that this channel has a custom url in format:
https://www.youtube.com/c/myname
but from tutorial and video i found i need to get the user from a custom url like this
https://www.youtube.com/user/myname
since, as far as i know, is not possible to set an url and surname based on second url for newer channel how can i found the username?
any way to get it with API?
youtube.channels.list does NOT provide the username. you have to use Google+ API to get it.
tube_dl is the answer.
pip install tube_dl
This module is a great video downloader and youtube parser.
Here's the sample code:
from tube_dl import Youtube
yt = Youtube('your video id').channelUrl
For tube_dl documentation, visit Github Page of tube_dl
You can try out the Channels.list method on the YouTube Data API. You can pass the username and it will return the list of channels that said user have.
The YouTube Data API developer site has more information if you want to learn more about it.
I have searched the web for tutorials and instructions but could not find any on this... So I was hoping maybe someone here can point me in the right direction or just link some good tutorials. (By the way I am willing to make a basic YouTube client app which lets the user search for videos and than watch them...nothing too fancy).
Thanks in advance!
Oh buddy.... welcome welcome to the world of parsing JSON files and putting up with BADLY documented APIs :)
Well I was looking into this a few months ago and I managed to get it working. Here are the things you have to do:
Step 1 - OAuth 2.0 Integration
Will your app allow the user to login to YouTube so that they can comment/like/etc... videos? If so, then you will need to get the user to login to the YouTube API via your app first before they can do these kind of things. In order to do that, your app will need to use OAuth 2.0 to communicate with the YouTube API. Here is a superb library which you can use to authenticate with the YouTube API via OAuth 2.0: https://github.com/BHughes3388/BAHYouTubeOAuth
Step 2 - Keychain - Access Token storage
If you are new to OAuth authentication, then it can be daunting at first, but once you play around with it and familiarize yourself with it, you will realize that it is very easy to work with.
So overall, the way it works, is that your app contacts the API (in this case YouTube V3 API) and requests a webpage. The webpage allows the user to login to the APi and grant your app access. Once this has been done, the API will send your app an "access token". This token will need to be used in all (or most) of your API requests (it depends on the type of request).
Once you have obtained the "access token" you will then need to store it securely. Its basically a password, so you need to keep it safe. Do not do what some people do, which is to use NSUserDefaults, that is not secure at all. Instead you will need to use Keychain. This is Apple's secure encryption/storage library which can easily be used to save secure strings such as passwords.
In order to use Keychain to securely store and retrieve the "access token" when you need it, take a look at this SO post, its great: How to use Keychain for saving password like GenericKeychain sample code
Step 3 - YouTube API V3 - https://developers.google.com/youtube/v3/
Right so now, the harder bit. You need to read through the Google YouTube API V3 and go through the API reference documents to find the specific URLs which will return the data you are looking for. For example: if you want to get a list of videos from the home feed of a user or from a simple search, then take a look at this API reference page: https://developers.google.com/youtube/v3/docs/videos/list
Step 4 - Extract the video URL
Before I talk further about this step, I should mention that Google says you should present videos in a simple webview with YouTube HTML code which simply embeds the video view in your app. But in my opinion (and many other devs), this looks and works horribly....
So if you want to display YouTube video in your app via the native MPMovieplayerController, then you will need to extract the video URL first before you can do this.
When you make a request to the YouTube API for a set of video(s), you will get a JSON file back, this file contains a list of videos (videoIDs, titles, dates, etc....).
You will need to parse the JSON file for the video IDs. Once you or the app user has selected the video that they want, you will need to use then pass the video ID for that particular video to a "YouTube video link extractor" library. This library will then return a set of video file links for that video. These links can be used in conjunction with MPMovieplayerController to display the video natively.
Here is a great YouTube video file url extracter - https://github.com/runmad/RMYouTubeExtractor
Good luck :)
How to get user specific recommended videos based on specific channel like - nba, nationalgeographic using YouTube API?
I am using the below API to get recommended videos.
https://gdata.youtube.com/feeds/api/users/default/recommendations?v=2&key=&access_token=
key -> I am passing my developer key
access_token -> I am passing authentication token.
Its returning me recommended videos of specific user. But I need recommended videos of specific channels like nba, nationalgeographic.
Can anyone please help for this.
I know this is old but in case anyone googling this comes across this answer, a workaround until there is a full recommendation API in YouTube API v3 is to use the Activity List feature, then just go through the results looking for "type": "recommendation":
https://developers.google.com/youtube/v3/docs/activities/list
GET https://www.googleapis.com/youtube/v3/activities?part=snippet&home=true&maxResults=50&key={YOUR_API_KEY}
(don't forget to use an auth token for a user for this to work)
I found that there is a api for user:
To request a feed of another user's favorite videos, send a GET request to the following URL. Note that this request does not require authentication.
https://gdata.youtube.com/feeds/api/users/userId/favorites
is there a api for video?, for example:
https://gdata.youtube.com/feeds/api/vidoes/videoId/favorites
I can't find anything in the Data API reference which would suggest that it is possible to read who liked a video, only how many people did: https://developers.google.com/youtube/2.0/reference and https://developers.google.com/youtube/2.0/developers_guide_protocol_ratings