0
Answer

Error Code 403

Ramco Ramco

Ramco Ramco

5d
76
1

Hi

  I am getting error - {
  "error": {
    "code": 403,
    "message": "The request cannot be completed because you have exceeded your \u003ca hef=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.",
    "errors": [
      {
        "message": "The request cannot be completed because you have exceeded your \u003ca hef=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.",
        "domain": "youtube.quota",
        "reason": "quotaExceeded"
      }
    ]
  }
}

In below code it is showing Null value.

tagResponse.Data.items

protected void MyOwnVideos11()
        {
            StringBuilder htmlTable = new StringBuilder();

            string nextPageToken = string.Empty;
            Int32 Sr = 1;
            var data0 = GetVideosList(nextPageToken);
            var orderByPublishAt = data0.items.OrderBy(x => x.snippet.publishedAt);

            htmlTable.Append("<table class='table table-bordered table-hover datatable-highlight' id='tbldata'>");
            htmlTable.Append("<thead><tr><th>Sr.</th><th>Video Title</th><th>Description</th><th>Views</th><th>Like</th><th>Comment</th><th>Published</th></tr></thead>");
            htmlTable.Append("<tbody>");

            nextPageToken = data0.nextPageToken;
            while (!string.IsNullOrEmpty(nextPageToken))
            {
                data0 = GetVideosList(nextPageToken);
                orderByPublishAt = data0.items.OrderBy(x => x.snippet.publishedAt);
                nextPageToken = data0.nextPageToken;
                foreach (var data in orderByPublishAt)
                {
                    var clientTag = new RestClient("googleapis.com/youtube/v3/");
                    var tagRequest = new RestRequest("videos", Method.GET);
                    tagRequest.AddParameter("key", "AIzaG8");
                    tagRequest.AddParameter("part", "snippet,statistics");
                    tagRequest.AddParameter("id", data.id.videoId);
                    var tagResponse = clientTag.Execute<VideoListResponse>(tagRequest);

                    foreach (var item in tagResponse.Data.items)
                    {
                        htmlTable.Append("<td >" + Sr + "</td>");
                        htmlTable.Append("<td></td>");
                        htmlTable.Append("<td >" + item.snippet.title + "</td>");
                        htmlTable.Append("<td >" + item.snippet.description + "</td>");

                        htmlTable.Append("<td >" + item.statistics.viewCount + "</td>");
                        htmlTable.Append("<td >" + item.statistics.likeCount + "</td>");
                        htmlTable.Append("<td >" + item.statistics.commentCount + "</td>");

                        htmlTable.Append("<td >" + data.snippet.publishedAt.ToString("dd-MM-yyyy") + "</td>");
                        htmlTable.Append("</tr>");
                        Sr = Sr + 1;
                    }
                }
            }
            htmlTable.Append("</tbody>");
            htmlTable.Append("</table>");
            PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
        }

private static YoutubeSearchListResponse GetVideosList(string nextPageToken)
        {
            var client = new RestClient("googleapis.com/youtube/v3");
            var request = new RestRequest("search", Method.GET);
            request.AddParameter("part", "snippet");
            request.AddParameter("type", "video");
            request.AddParameter("channelId", "UoaVw");
            request.AddParameter("key", "AIzaG8");
            if (!string.IsNullOrEmpty(nextPageToken))
            {
                request.AddParameter("pageToken", nextPageToken);
            }
            var response = client.Execute<YoutubeSearchListResponse>(request);

            return response.Data;
        }

Thanks