尝试使用 R 和库 ROAuth 连接到 yelp API。
使用 rauth 模块和地理坐标的很棒的 python 示例:
https://gist.github.com/phillipjohnson/8889618 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")
但没有超越握手。 Yelp 使用 ROAuth 包支持的 OAuth 1.0。从其他代码中我看到它需要“oauth_consumer_key”、“oauth_nonce”、“oauth_signature_method”、“oauth_timestamp”、“oauth_token”。我非常感谢那些使用 R 通过地理坐标查询 Yelp 的人提供的任何提示。谢谢!
在 ROAuth 的作者推荐使用库(httr)之后,并且由于 R 中缺乏使用这两个库的简单 yelp 示例,我认为其他人可能也在寻找这个。这将按名称返回芝加哥地区的 10 个酒吧,或按地理坐标返回旧金山的 10 个酒吧。将 x 替换为您自己的 yelp 帐户密钥。 (这是从许多来源拼凑而成的 - 感谢他们所有人)。
# 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))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)