Reputation: 639
I use the YouTube Data API to get some information from a query result (videos).
The most videos return their data correct. But some videos don't return their channel title (all other fields return correct anyway).
com.google.api.services.youtube.YouTube.Search.List search = youtube.search().list("id,snippet");
search.setKey(getString(R.string.APIKEYYOUTUBE));
search.setQ("hi");
search.setType("video");
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/medium/url,snippet/channelTitle,snippet/publishedAt)");
search.setMaxResults(7);
[...]
String vId = rId.getVideoId();
String test = singleVideo.getSnippet().getChannelTitle();
Example:
Second video returned:
vId = "Kgw9xKQX-dI"
test = "htmailru"
Third video returned :
vId = "Q_6XNufgvA4"
test = ""
But if I proof the third video ID in youtube it has (as expected) a channel title.
Any ideas?
Upvotes: 0
Views: 826
Reputation: 673
It looks like this issue was reported almost two years ago, but unfortunately there hasn't yet been a response from Google. The reporter indicated that channelTitle
returned blank whenever the channel title included a space. (In your example, the channel title for Q_6XNufgvA4 is "World's Best Videos," which indeed includes a space.)
https://code.google.com/p/gdata-issues/issues/detail?id=6104
Fortunately, as a workaround, channelTitle
does appear to populate correctly when returned from videos.list
and channels.list
.
videos.list:
Using videoId
from the search response
GET https://www.googleapis.com/youtube/v3/videos?part=snippet&
id=Q_6XNufgvA4&
fields=items%2Fsnippet%2FchannelTitle&
key={YOUR_API_KEY}
returns
{
"items": [
{
"snippet": {
"channelTitle": "World's Best Videos"
}
}
]
}
channels.list:
You can get channelId
from your search response (items/snippet/channelId
) and send a request as follows.
GET https://www.googleapis.com/youtube/v3/channels?part=snippet&
id=UCHqBLGGOvojeQswyJptjukA&
fields=items%2Fsnippet%2Ftitle&
key={YOUR_API_KEY}
returns
{
"items": [
{
"snippet": {
"title": "World's Best Videos"
}
}
]
}
Upvotes: 2