将Yelp API与R一起使用,尝试使用地理坐标搜索业务类型

amu*_*gui 1 r yelp

尝试使用R和库ROAuth连接到yelp API.

使用rauth模块和地理坐标的伟大python示例:

https://gist.github.com/phillipjohnson/8889618

并希望在R中使用像ROAuth这样的库来做到这一点.

我一直试图创造握手等:

credentials <- OAuthFactory$new(consumerKey=consumerKey,
                                consumerSecret=consumerSecret,
                                oauthKey = token,
                                oauthSecret = token_secret,
                                authURL="http://api.yelp.com/v2")
credentials$handshake()
credentials$OAuthRequest(testURL, "GET")
Run Code Online (Sandbox Code Playgroud)

但是没有通过握手.Yelp使用ROAuth包支持的OAuth 1.0.从其他代码我已经看到了它需要一个 'oauth_consumer_key', 'oauth_nonce', 'oauth_signature_method', 'oauth_timestamp', '组oauth_token'.我很感激使用R来使用地理坐标查询Yelp的人的任何提示.谢谢!

amu*_*gui 8

在ROAuth的作者推荐使用库(httr)之后,由于R中使用任何一个库缺少简单的yelp示例,我想其他人也可能正在寻找这个.这将按名称返回芝加哥地区的10个酒吧,或按地理坐标返回旧金山的10个酒吧.用您自己的yelp帐户密钥替换x.(这是从许多来源拼凑而成的 - 感谢所有这些来源).

# 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))
Run Code Online (Sandbox Code Playgroud)