Ramco Ramco

Ramco Ramco

  • 443
  • 3.4k
  • 533.7k

Traffic Search Keywords

Apr 16 2024 4:35 AM

Hi

  I have below code but it is giving error on this line

dynamic videoListData = JsonConvert.DeserializeObject(videoListResponse.Content);

  Name Value Type
? $exception {"Unexpected character encountered while parsing value: <. Path '', line 0, position 0."} Newtonsoft.Json.JsonReaderException
var videoIds = new List<string>();
var client = new RestClient("googleapis.com/youtube/analytics/v1/reports");
var request = new RestRequest("query", Method.GET);

request.AddParameter("ids", "channel==UCg3Zpk-m_nNoaVw");
request.AddParameter("metrics", "views");
request.AddParameter("dimensions", "insightTrafficSourceType,insightTrafficSourceDetail");
request.AddParameter("key", "AIG8");
request.AddParameter("type", "video");
request.AddParameter("maxResults", "50");
do
{
    var videoListResponse = client.Execute(request);
    dynamic videoListData = JsonConvert.DeserializeObject(videoListResponse.Content);

    foreach (var item in videoListData.items)
    {
        videoIds.Add(item.id.videoId.ToString());
    }

    // Check if there are more pages of results
    if (videoListData.nextPageToken != null)
    {
        request.AddParameter("pageToken", videoListData.nextPageToken);
    }
    else
    {
        break; // No more pages, exit the loop
    }
} while (true);

Answers (3)