0
$\begingroup$

Updated to show more code

Can't seem to find a good post/answer to this so I'm asking the question.

I'm pulling data from the Swarm/Foursquare API, and it's paged (max 250 results per pull):

url = StringTemplate[ "https://api.foursquare.com/v2/users/self/checkins?startTime=`a`&\ endTime=`b`&oauth_token=`c`&limit=250&offset=`d`&v=20220406"][<| "a" -> startTime, "b" -> endTime, "c" -> oauthToken, "d" -> offset|>]; response = Import[url, "RawJSON"]; checkins = response[["response"]][["checkins"]][["items"]]; Until[Length[response[["response"]][["checkins"]][["items"]]] == 0, offset += 250; url = StringTemplate[ "https://api.foursquare.com/v2/users/self/checkins?startTime=`a`&\ endTime=`b`&oauth_token=`c`&limit=250&offset=`d`&v=20220406"][<| "a" -> startTime, "b" -> endTime, "c" -> oauthToken, "d" -> offset|>]; response = Import[url, "RawJSON"]; AppendTo[checkins, response[["response"]][["checkins"]][["items"]]] ] 

I should have around 1,200 results. Instead, I have 256. What am I doing wrong here?

$\endgroup$
5
  • $\begingroup$ Are you having trouble only combining the results? Or do you need help with the logic to continue to download until there are no more results? $\endgroup$ Commented Sep 19, 2022 at 16:35
  • $\begingroup$ I updated the post to show the complete code I'm trying to use. $\endgroup$ Commented Sep 19, 2022 at 18:36
  • $\begingroup$ Figured out on my own. apparently have to go one at a time: ``` Do[ AppendTo[checkins, response[["response"]][["checkins"]][["items"]][i]], {i, 0, Length[response[["response"]][["checkins"]][["items"]]]} ] ``` $\endgroup$ Commented Sep 19, 2022 at 18:45
  • $\begingroup$ The problem is that you are appending the subsequent result lists as a single item to your list. You need to Join the two lists instead, so checkins = Join[checkins, response[["response", "checkins", "items"]]] should do the trick $\endgroup$ Commented Sep 20, 2022 at 8:22
  • $\begingroup$ Thank you, @LukasLang, that's more efficient than what I came up with. :-) $\endgroup$ Commented Sep 21, 2022 at 12:54

1 Answer 1

1
$\begingroup$

Apparently I have to go one at a time on the Append:

Do[ AppendTo[checkins, response[["response"]][["checkins"]][["items"]][i]], {i, 0, Length[response[["response"]][["checkins"]][["items"]]]} ] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.