整天都在乱搞这一天。我只是试图从Strava下拉数据来操纵R,但我无法解决这个问题。我不是程序员,但是一旦连接到github文件我就完成了这个,但事情并没有按照我的方式进行。
这是一个基本错误还是我错过了一些我不理解的更深层原则?
这是我尝试运行代码时得到的结果:
x <- pullStravaData();
> x
<Token>
<oauth_endpoint>
request: https://www.strava.com/oauth/authorize
authorize: http://localhost:1410
access: https://www.strava.com/oauth/token
client_id: 3979
response_type: code
<oauth_app> strava
key: XX # I hid this, not sure if it matters
secret: <hidden>
<credentials> message, errors
这是我的代码:
pullStravaData <- function() {
# because I think this is important
library(httr);
# not sure if this is relevant
responseType = "code";
clientId = 3979;
# create app
clientSecret = trust_that_i_entered_this;
accessToken = and_this_wrapped_in_quotes;
myapp <- oauth_app("strava", accessToken, clientSecret);
# get oauth credentials
request <- "https://www.strava.com/oauth/authorize";
authorize <- "http://localhost:1410";
access <- "https://www.strava.com/oauth/token";
strava_token <- oauth2.0_token(
oauth_endpoint(request, authorize, access),
myapp);
data <- stravaPost(strava_token, clientId, clientSecret);
}
stravaPost <- function(token, clientId, clientSecret) {
# I saw this happen somewhere else, but I'm pretty sure my script doesn't even get here
stoken = config(token=token);
req <- GET(sprintf("https://www.strava.com/api/v3/activities/%s",
clientId), stoken, client_id = clientId, client_secret = clientSecret, code = token);
stop_for_status(req); # not sure what this does
content(req); # not sure what this does
}
答案 0 :(得分:0)
按顺序:
你没有在pullStravaData函数中使用任何类型的显式或隐式return()。结果是它实际上并没有返回“数据”。试着转身:
data <- stravaPost(strava_token, clientId, clientSecret);
进入:
data <- stravaPost(strava_token, clientId, clientSecret);
return(data)
或只是:
stravaPost(strava_token, clientId, clientSecret);
..看看会发生什么。虽然我们在这里,顺便说一下,分号是不必要的。
我强烈建议,如果你要用R手动制作这些类型的请求,你就会知道语言是如何运作的,以及它的规则是什么。我听说this非常好。