Bring the following set of images to RestSharp

I am trying to create an endless table in Xamarin as an Instagram client. However, when I look at the bottom of the screen, it loads the same second page of images back. It loads the first page normally, then it loads the second page normally, however, when I try to load the third page, it loads the second page again. How to fix it? This is how I try to download it:

Account instagram = enumerable.First ();
var instagramAccessToken = instagram.Properties ["access_token"].ToString ();

var request = new RestRequest { RootElement = "data", Resource = "/users/self/feed" };
request.AddParameter ("access_token", instagramAccessToken);

var client = new RestClient ("https://api.instagram.com/v1");
client.ExecuteAsync (request, response => {
    var rootObject = JsonConvert.DeserializeObject<RootObject> (response.Content);

    string nextURL = rootObject.pagination.next_url;
    //// Create Next Client
    var requestBack = new RestRequest ();
    var clientBack = new RestClient (nextURL);

    // GET Next Response
    clientBack.ExecuteAsync (requestBack, responseBack => {
        var rootObjectBack = JsonConvert.DeserializeObject<RootObject> (responseBack.Content);
        table.InvokeOnMainThread (() => {
            // Create list that contains newly attained JSON
            List<Datum> instagramData = rootObjectBack.data;
            // Create dummy list for other values
            List<Datum> sloppy = null;
            ((TableSource<Datum>)table.Source).instaData.AddRange (instagramData);
            table.ReloadData ();
            });
        });
    });

Here I find that the user is at the bottom of the TableView

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
    {

        NetworkCheck netCheck = new NetworkCheck ();
        netCheck.runCheck ();
        bool log = netCheck.anyLoggedIn ();

        if (tableView.ContentSize.Height - UIScreen.MainScreen.Bounds.Height <= tableView.ContentOffset.Y) {
            // this is the last row in the last section
            Console.WriteLine ("~~~Bottom~~~");
            FLDTRequest fldt = new FLDTRequest ();
            fldt.getPastInstagramFeed (tableView);
        }
        var cell = tableView.DequeueReusableCell(InstagramCell.Key) as InstagramCell;

        if (cell == null)
        {
            cell = new InstagramCell();
            var views = NSBundle.MainBundle.LoadNib("InstagramCell", cell, null);
            cell = Runtime.GetNSObject(views.ValueAt(0)) as InstagramCell;
        }

        Datum h = instaData [indexPath.Row];
        cell.BindData(h);

        return cell;
    }
+4
source share
1 answer

, , nexturl. API- instagram, - .

viewdidload - ( , , )

nextUrl = null;

Account instagram = enumerable.First ();
var instagramAccessToken = instagram.Properties ["access_token"].ToString ();

var request = new RestRequest { RootElement = "data", Resource = "/users/self/feed" };
request.AddParameter ("access_token", instagramAccessToken);

var client = new RestClient ("https://api.instagram.com/v1");
client.ExecuteAsync (request, resp =>
    {
        PageRetrievedCallback(resp );
    });

nextUrl

string nextUrl = null;

public void PageRetrievedCallback(RestResponse response)
{
    var rootObject = JsonConvert.DeserializeObject<RootObject> (response.Content);
    nextURL = rootObject.pagination.next_url;

    table.InvokeOnMainThread (() => {
            // Create list that contains newly attained JSON
            List<Datum> instagramData = rootObject.data;
            // Create dummy list for other values
            List<Datum> sloppy = null;
            ((TableSource<Datum>)table.Source).instaData.AddRange (instagramData);
            table.ReloadData ();
         });
}

, :

if ( ! string.IsNullOrEmpty (nextURL) ) 
{

    var requestBack = new RestRequest ();
    var clientBack = new RestClient (nextURL);
    clientBack.ExecuteAsync (requestBack, resp =>
    {
        PageRetrievedCallback(resp );
    });
}
+1

Source: https://habr.com/ru/post/1545416/


All Articles