Using the Yelp API with R, attempting to search business types using geo-coordinates

后端 未结 1 2085
遇见更好的自我
遇见更好的自我 2020-12-30 17:48

Trying to connect to the yelp API using R and library ROAuth.

Great python sample using the rauth module and geo-coordinates:

https://gist.github.com/phill

相关标签:
1条回答
  • 2020-12-30 18:19

    After the author of ROAuth recommended using library(httr) and because of the lack of simple yelp examples in R using either libraries, I figured others may be looking for this too. This will return either 10 bars in the Chicago area by name, or 10 bars in San Francisco by geo-coordinates. Replace the x's with your own yelp account keys. (this is pieced together from many sources- thanks to all of them).

    # yelp
    consumerKey = "xxxx"
    consumerSecret = "xxxx"
    token = "xxxx"
    token_secret = "xxxx"
    
    require(httr)
    require(httpuv)
    require(jsonlite)
    # authorization
    myapp = oauth_app("YELP", key=consumerKey, secret=consumerSecret)
    sig=sign_oauth1.0(myapp, token=token,token_secret=token_secret)
    
    limit <- 10
    
    # 10 bars in Chicago
    yelpurl <- paste0("http://api.yelp.com/v2/search/?limit=",limit,"&location=Chicago%20IL&term=bar")
    # or 10 bars by geo-coordinates
    yelpurl <- paste0("http://api.yelp.com/v2/search/?limit=",limit,"&ll=37.788022,-122.399797&term=bar")
    
    locationdata=GET(yelpurl, sig)
    locationdataContent = content(locationdata)
    locationdataList=jsonlite::fromJSON(toJSON(locationdataContent))
    head(data.frame(locationdataList))
    
    0 讨论(0)
提交回复
热议问题