Question

I have been using youtube API V3 in my application.I have referred this link to retrieve the search results associated with the keyword.

    public static void Search(string keyword, ref List<string> videoList)
    {
        // Validate keyword
        if (string.IsNullOrWhiteSpace(keyword))
        {
            return;
        }
        // Create a youtube service
        YoutubeService youtube = new YoutubeService(new BaseClientService.Initializer()
        {
            ApiKey = GoogleCredentials.apiKey
        });

        SearchResource.ListRequest listRequest = youtube.Search.List("snippet");
        listRequest.Q = keyword;
        listRequest.Order = SearchResource.Order.Rating;

        // Fetch the response from youtube
        SearchListResponse searchResponse = listRequest.Fetch();


        foreach (SearchResult searchResult in searchResponse.Items)
        {
            videoList.Add(searchResult.Id.VideoId);
        }
    }

In this line of code

        SearchListResponse searchResponse = listRequest.Fetch();

It throws the following error.

An unhandled exception of type 'Google.GoogleApiRequestException' occurred in Google.Apis.dll Additional information: Google.Apis.Requests.RequestError

  Bad Request [400]

What could be the problem?

Was it helpful?

Solution

I have made a silly mistake ..Instead of using the API Key I have used the client secret. After replacing it ,the error was resolved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top