WoBike
WoBike copied to clipboard
Bird API 400 Issue
I have been trying to create an API for the Bird bikes in R, but I'm getting a 400 error when it comes to getting the bike data.
The query to get the token works fine, but it seems that the way I am structuring my GET request is not hitting correctly.
library(tidyverse)
library(httr)
bird_auth_key <- function(email, guid){
url <- "https://api.birdapp.com/user/login"
resp <- POST(
url,
add_headers(
`User-Agent` = "Bird/4.41.0 (co.bird.Ride; build:37; iOS 12.3.1) Alamofire/4.41.0",
`Device-ID` = guid,
Platform = 'ios',
`App-Version` = '4.41.0',
`Content-Type` = "application/json"
),
body = list(email = email),
encode = "json"
)
resp
}
GUID <- "bf755982-ed58-4b1d-8032-b7554c4d2559"
value <- bird_auth_key("[email protected]", GUID)
token <- content(value, "text")
Location <- tibble(
latitude = 37.77249,
longitude = -122.40910,
altitude = 500,
accuracy = 100,
speed = 1,
heading = 1)
bird_get_location <- function(token, guid, location){
url <- str_interp("https://api.birdapp.com/bird/nearby?latitude=${location$latitude}&longitude=${location$longitude}&radius=1000")
print(url)
resp <- GET(
url,
add_headers(
Authorization = str_interp("Bird ${token}"),
`Device-ID` = guid,
`App-Version` = '4.41.0',
location = jsonlite::toJSON(location)
),
encode = "json"
)
resp
}
Token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBVVRIIiwidXNlcl9pZCI6IjI0NDBjNTM1LTliYzQtNDZhNC1hNTQ1LTJiYzAxMzBlMmFhNCIsImRldmljZV9pZCI6ImJmNzU1OTgyLWVkNTgtNGIxZC04MDMyLWI3NTU0YzRkMjU1OSIsImV4cCI6MTU5OTQyMTQxMn0.1cmI9gc8_NN_8IagyB8hu88MiDYY8SHReF8cj4PSkfI"
bird_get_location(Token, GUID, Location)
I looked at the Node library for reference, but it seems the code is gone.
hi, at first glance it looks good, i copied essentials to Postman and it executes just fine. could you paste curl input you test that with or just plain calls that this code is trying to execute?
So like you did, I tested in postman, and the request worked fine as you did,
As for the request, I have been doing it with the httr
package in R.
This is the code I am trying to execute
bird_get_location <- function(token, guid, location){
url <- str_interp("https://api.birdapp.com/bird/nearby?latitude=${location$latitude}&longitude=${location$longitude}&radius=1000")
print(url)
resp <- GET(
url,
add_headers(
`Authorization` = str_interp("Bird ${token}"),
`Device-id` = guid,
`App-Version` = '4.41.0',
`Location` = jsonlite::toJSON(location %>% flatten(), pretty = TRUE, auto_unbox = TRUE)
),
encode = "json",
query = list(params = jsonlite::toJSON(location %>% flatten(), pretty = TRUE, auto_unbox = TRUE))
)
resp
}
Token = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBVVRIIiwidXNlcl9pZCI6IjI0NDBjNTM1LTliYzQtNDZhNC1hNTQ1LTJiYzAxMzBlMmFhNCIsImRldmljZV9pZCI6ImJmNzU1OTgyLWVkNTgtNGIxZC04MDMyLWI3NTU0YzRkMjU1OSIsImV4cCI6MTU5OTQyMTQxMn0.1cmI9gc8_NN_8IagyB8hu88MiDYY8SHReF8cj4PSkfI"
GUID <- "bf755982-ed58-4b1d-8032-b7554c4d2559"
Location <- tibble(
latitude = 37.77249,
longitude = -122.40910,
altitude = 500,
accuracy = 100,
speed = -1,
heading = -1)
bird_get_location(Token, GUID, Location)
EDIT: Here is the curl request I was using
curl -X GET \
'https://api.birdapp.com/bird/nearby?latitude=37.77184&longitude=-122.40910&radius=1000' \
-H 'App-Version: 4.41.0' \
-H 'Authorization: Bird eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBVVRIIiwidXNlcl9pZCI6IjI0NDBjNTM1LTliYzQtNDZhNC1hNTQ1LTJiYzAxMzBlMmFhNCIsImRldmljZV9pZCI6ImJmNzU1OTgyLWVkNTgtNGIxZC04MDMyLWI3NTU0YzRkMjU1OSIsImV4cCI6MTU5OTQyMTQxMn0.1cmI9gc8_NN_8IagyB8hu88MiDYY8SHReF8cj4PSkfI' \
-H 'Device-id: bf755982-ed58-4b1d-8032-b7554c4d2559' \
-H 'Location: {"latitude":37.77249, "longitude":-122.40910, "altitude":500,"accuracy":100,"speed":-1,"heading":-1}'