Skip to content

Instantly share code, notes, and snippets.

@patperu
Last active September 8, 2024 12:32
Show Gist options
  • Save patperu/68e8013c866e9dec0c72 to your computer and use it in GitHub Desktop.
Save patperu/68e8013c866e9dec0c72 to your computer and use it in GitHub Desktop.
Receive data from the ImmobilienScout24-API
library(httr)
library(jsonlite)
library(tidyverse)
# Keys, but it's better to set up
# environment variables via 'Sys.setenv'
consumerKey <- "aaa"
consumerSecret <- "bbb"
immo24_app <- oauth_app(appname = "app",
key = consumerKey,
secret = consumerSecret)
url <- "https://rest.immobilienscout24.de/restapi/api/search/v1.0/search/region?realestatetype=apartmentrent&geocodes=1276003001"
signature <- oauth_signature(url, method = "GET", app = immo24_app)
res <- GET(url, oauth_header(signature))
stop_for_status(res)
text <- content(res, as = 'text', encoding="UTF-8")
glimpse(fromJSON(text))
# List of 1
# $ resultlist.resultlist:List of 2
# ..$ paging :List of 6
# .. ..$ next :List of 1
# .. ..$ pageNumber : int 1
# .. ..$ pageSize : int 20
# .. ..$ numberOfPages : int 109
# .. ..$ numberOfHits : int 2162
# .. ..$ numberOfListings: int 2162
# ..$ resultlistEntries:'data.frame': 1 obs. of 3 variables:
# .. ..$ @numberOfHits : chr "2162"
# .. ..$ @realEstateType: chr "0"
# .. ..$ resultlistEntry:List of 1
glimpse(fromJSON(text)$resultlist.resultlist$resultlistEntries$resultlistEntry)
# List of 1
# $ :'data.frame': 20 obs. of 10 variables:
# ..$ @xlink.href : chr [1:20] "https://rest.immobilienscout24.de/restapi/api/search/v1.0/expose/114437..." "--" "--" "--" ...
# ..$ @id : chr [1:20] "11443..." "11347..." "11787..." "11713..." ...
# ..$ @modification : chr [1:20] "2020-05-08T11:43:00.609+02:00" "2020-01-02T09:31:53.025+01:00" "2020-04-30T14:38:21.206+02:00" "2020-05-01T20:07:03.548+02:00" ...
# ..$ @creation : chr [1:20] "2019-11-13T17:12:09.000+01:00" "2019-09-11T18:00:13.000+02:00" "2020-04-30T14:48:43.000+02:00" "2020-04-08T20:10:51.000+02:00" ...
# ..$ @publishDate : chr [1:20] "2019-11-13T17:12:09.000+01:00" "2019-09-11T18:00:13.000+02:00" "2020-04-30T14:48:43.000+02:00" "2020-04-08T20:10:51.000+02:00" ...
# ..$ realEstateId : int [1:20] "--" "--" "--" "--"...
# ..$ newHomeBuilder : chr [1:20] "false" "false" "false" "false" ...
# ..$ disabledGrouping : chr [1:20] "false" "false" "false" "false" ...
# ..$ resultlist.realEstate:'data.frame': 20 obs. of 23 variables:
# .. ..$ @xsi.type : chr [1:20] "search:ApartmentRent" "search:ApartmentRent" "search:ApartmentRent" "search:ApartmentRent" ...
# .. ..$ @id : chr [1:20] "11443..." "11347..." "11787..." "1171..." ...
# .. ..$ title : chr [1:20] "--" "--" "--" "--" ...
# .. ..$ address :'data.frame': 20 obs. of 7 variables:
# .. ..$ companyWideCustomerId : chr [1:20] "002.01000793336" "001.15652831" "001.6749" "001.63" ...
# .. ..$ titlePicture :'data.frame': 20 obs. of 8 variables:
# .. ..$ floorplan : chr [1:20] "true" "true" "true" "false" ...
# .. ..$ streamingVideo : chr [1:20] "false" "false" "false" "false" ...
# .. ..$ listingType : chr [1:20] "XL" "XL" "XL" "XL" ...
# .. ..$ showcasePlacementColor : chr [1:20] "#FF7800" "#343434" "#343434" "#343434" ...
# .. ..$ privateOffer : chr [1:20] "false" "false" "false" "false" ...
# .. ..$ realtorLogo : chr [1:20] "--" "--" "--" "--" ...
# .. ..$ realtorCompanyName : chr [1:20] "--" "--" "--" "--" ...
# .. ..$ realtorLogoForResultList :'data.frame': 20 obs. of 5 variables:
# .. ..$ price :'data.frame': 20 obs. of 4 variables:
# .. ..$ livingSpace : num [1:20] 125 186 140 136 133 ...
# .. ..$ numberOfRooms : num [1:20] 4 2 3 3 3 4 4 3.5 4 2 ...
# .. ..$ energyPerformanceCertificate: chr [1:20] "true" NA "true" "true" ...
# .. ..$ energyEfficiencyClass : chr [1:20] "B" NA NA "B" ...
# .. ..$ builtInKitchen : chr [1:20] "false" "true" "false" "true" ...
# .. ..$ balcony : chr [1:20] "true" "true" "true" "false" ...
# .. ..$ garden : chr [1:20] "true" "false" "true" "false" ...
# .. ..$ calculatedPrice :'data.frame': 20 obs. of 5 variables:
# ..$ hasNewFlag : chr [1:20] "false" "false" "true" "false" ...
x <- fromJSON(text)$resultlist.resultlist$resultlistEntries$resultlistEntry
x <- x[[1]]$resultlist.realEstate
x
glimpse(x)
#
# FINI
#
@e-orlov
Copy link

e-orlov commented Sep 8, 2024

despite consumerKey and consumerSecret, error Could not resolve host: rest.immobilienscout24.de while run at https://rdrr.io/snippets/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment