使用youtube API V3 for C#时出错

时间:2013-08-08 10:16:05

标签: c# youtube-api google-api youtube.net-api

我一直在我的应用程序中使用youtube API V3。我已经引用了这个link来检索与该关键字相关联的搜索结果。

    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);
        }
    }

在这行代码中

        SearchListResponse searchResponse = listRequest.Fetch();

它会抛出以下错误。

  

Google.Apis.dll中发生未处理的“Google.GoogleApiRequestException”类型异常        其他信息:Google.Apis.Requests.RequestError

  Bad Request [400]

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我犯了一个愚蠢的错误..而不是使用API​​密钥我使用了客户端秘密。更换后,错误得到了解决。