2014-10-05 33 views
4

我一直在試圖使用基於來自Reddit's github這個例子RCurl來自R與reddit的驗證與認證書籤交易:如何使用RCurl

curl -X POST -d 'grant_type=password&username=reddit_bot&password=snoo' --user 'p-jcoLKBynTLew:gko_LXELoV07ZBNUXrvWZfzE3aI' https://ssl.reddit.com/api/v1/access_token 

我試圖將其轉換爲一個RCurl命令,像這樣:

postForm("https://ssl.reddit.com/api/v1/access_token?grant_type=password", 
    username = "MyUserName", 
    password = "MyPassword", 
    .opts = list(userpwd = "MyClientid:MySecret") 
    ) 

但我得到一個錯誤:Error: Unauthorized

我不知道,我使用curl命令Rcurl的轉換做什麼真的。感謝您提供的任何幫助!

回答

3

試試這個HTTR代碼:

library(httr) 

POST("https://ssl.reddit.com/api/v1/access_token", 
    body = list(
    grant_type = "password", 
    username = "MyUserName", 
    password = "MyPassword" 
), 
    encode = "form", 
    authenticate("p-jcoLKBynTLew", "gko_LXELoV07ZBNUXrvWZfzE3aI") 
) 
+0

,完美的工作,謝謝!對於任何碰到此問題的人來說,grant_Type中的「T」需要小寫才能工作。 – Nick 2014-10-07 04:16:50