C# - Get All Followers - pagination cursor

plz help me achieve this !
I’m trying to get all Followers , but don’t know how to send a new call with the cursor …

I’m completly noob in programming , even more in C# , but for now I can get only the first 100 and the cursor …

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
using System.Net.Http;
using System.Net.Http.Headers;

public class ObjectData
{
public KeyValue TwitchOAuth { get; set; }
}
public class KeyValue
{
public string Token { get; set; }
}

public class Root
{
public int Total { get; set; }
public List Data { get; set; }
public Pagination Pagination { get; set; }
}
public class Datum
{
public string From_id { get; set; }
public string From_login { get; set; }
public string From_name { get; set; }
public string To_id { get; set; }
public string To_login { get; set; }
public string To_name { get; set; }
public DateTime Followed_at { get; set; }
}
public class Pagination
{
public string Cursor { get; set; }
}

public class AllDatas
{
public int TotalNb { get; set; }

public List<DateTime> Since { get; set; }
public List<string> UserName { get; set; }
public string TheCursor { get; set; }

}

namespace CleanAPIRequestApp
{
class Program
{

    public static void Main()
    {
        Task<AllDatas> getAllDatasTask = FunctionGetAllDatas();
        getAllDatasTask.Wait();
        AllDatas mydatas = getAllDatasTask.Result;
        Console.WriteLine(mydatas.TheCursor);

        int total = mydatas.TotalNb;
        for (int j = 0; j < total; j++)
        {
            Console.WriteLine(mydatas.UserName[j]);
        }
		// ▲ je demande a afficher l'ensemble des résultats obtenus 
    }
    public static string FunctionGetMyAPIToken() // je prends mon token 
    {
        string jsonFile;
        string tokenDirectory = ("C:\\Streamer.bot\\data\\settings.json");
        jsonFile = File.ReadAllText(tokenDirectory);
        ObjectData objectdata = JsonConvert.DeserializeObject<ObjectData>(jsonFile);
        string tokenValue = objectdata.TwitchOAuth.Token;
        return tokenValue;
    }

    public static HttpClient client = new HttpClient();
    public static async Task<Root> FunctionCallTwitchAPI(string cursor) //(j'appel l'API, désérialise le résultat)
    {
        string to_id = 493163649.ToString();  //   In Streamer.Bot ONLY ► to_id = args["broadcastUserId"].ToString();
        string tokenValue = FunctionGetMyAPIToken();
        client.DefaultRequestHeaders.Add("client-ID", "dnafsrivhw88gj7eltolrsq6794teq");
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenValue);
        HttpResponseMessage response = await
        client.GetAsync("https://api.twitch.tv/helix/users/follows?to_id=" + to_id + "&first=100&after=" + cursor);
        HttpContent responseContent = response.Content;
        string responseBody = await response.Content.ReadAsStringAsync();
        Root root = JsonConvert.DeserializeObject<Root>(responseBody);
        return root;

    }
    public static async Task<string> FunctionPushCursorData() // ( je réinjecte la donnée cursor dans l'appel initial )
    {
        string cursor = null;
        while (cursor != null)
        {
            Root root = await FunctionCallTwitchAPI(cursor);
            cursor = root.Pagination.Cursor;
        }
        Console.WriteLine(cursor);
        return cursor;
    }


    public static async Task<AllDatas> FunctionGetAllDatas() // je stock dans une nouvelle classe les données qui m'intéresse 
	
	// C'est ICI qu'il me faut boucler pour obtenir les blocks suivant ... [ Je suis bloqué ] 
	
        {
            
        string cursor = await FunctionPushCursorData().ConfigureAwait(true);
        Root root = await FunctionCallTwitchAPI(cursor);

        int totalFollowerNumber = root.Total;

        List<string> getUserName = new List<string>();
        List<DateTime> getSince = new List<DateTime>();
        var currentCount = 0;
        do
        {
            for (int i = 0; i < 100 ; i++)
            {
                currentCount += 1;
                getSince.Add(root.Data[i].Followed_at);
                getUserName.Add(root.Data[i].From_name);
            };
            return new AllDatas()
            {
                UserName = getUserName,
                Since = getSince,
                TotalNb = root.Total,
                TheCursor = root.Pagination.Cursor
        };
        } while (currentCount < totalFollowerNumber);
    }
}

}

this is now SOLVED.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.