Youtube V3 API - How to set APIKey
java, youtube, youtube-api
Solution
I figured out through another post.
The apiKey is set like this -
`
youtube = new YouTube.Builder(new NetHttpTransport(), JSON_FACTORY, new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
}
}).**setYouTubeRequestInitializer(new YouTubeRequestInitializer(apiKey)**.setApplicationName("youtube-cmdline-search-sample").build();
`
Problem
Youtube API newbie here. I cant seem to figure out how to set an APIKey while running queries that do not require a oAuth. I haven't been able to find any examples as well. I am trying to invoke VideoCategories.List using Java API like this - ` ``` String apiKey = properties.getProperty("youtube.apikey"); // Where does this go.? youtube = new YouTube.Builder(new NetHttpTransport(), JSON_FACTORY, new HttpRequestInitializer() { @Override public void initialize(HttpRequest httpRequest) throws IOException { } }).setApplicationName("youtube-cmdline-search-sample").build(); List<VideoCategory> categories = youtube.videoCategories().list("snippet").setRegionCode("US").execute().getItems(); ``` ` However, I cant figure out a place holder to set my apiKey. Any help would be appreciated.