Skip to content

Instantly share code, notes, and snippets.

@objmagic
Created May 17, 2015 20:13
Show Gist options
  • Select an option

  • Save objmagic/6d642feb1150de39aca7 to your computer and use it in GitHub Desktop.

Select an option

Save objmagic/6d642feb1150de39aca7 to your computer and use it in GitHub Desktop.
iter
let get_follower ~access_token ~screen_name ?(count=5000) ?(wait=true) () =
let base_uri = "https://api.twitter.com/1.1/followers/ids.json" in
let cursor = ref (-1) in
let f g () =
Client.do_get_request
~uri_parameters:
["screen_name", screen_name;
"cursor", (string_of_int (!cursor));
"count", (string_of_int count)]
~uri:(Uri.of_string base_uri)
~access_token:access_token
() >>= fun res ->
match res with
| Ok (header, str) -> begin
match (Yojson.Safe.from_string str |> user_ids_of_yojson) with
| `Ok uids ->
g state; (* handle states update *)
return (Some (Ok uids))
| `Error msg -> failwith msg
end
| Error e -> return (Some (Error (process_error_exn e))) in
Lwt_stream.from (f some_g)
let get_follower ~access_token ~screen_name ?(count=5000) ?(wait=true) () =
let base_uri = "https://api.twitter.com/1.1/followers/ids.json" in
let cursor = ref (-1) in
let f () =
Client.do_get_request
~uri_parameters:
["screen_name", screen_name;
"cursor", (string_of_int (!cursor));
"count", (string_of_int count)]
~uri:(Uri.of_string base_uri)
~access_token:access_token
() >>= fun res ->
match res with
| Ok (header, str) -> begin
match (Yojson.Safe.from_string str |> user_ids_of_yojson) with
| `Ok uids ->
cursor := uids.next_cursor;
return (Some (Ok uids))
| `Error msg -> failwith msg
end
| Error e -> return (Some (Error (process_error_exn e))) in
Lwt_stream.from f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment