【问题标题】:How to authenticate with reddit using RCurl如何使用 RCurl 向 reddit 进行身份验证
【发布时间】:2014-11-30 04:50:20
【问题描述】:

我一直在尝试使用基于Reddit's github 的示例的 RCurl 从 R 向 Reddit 进行身份验证:

 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 的真正目的是什么。感谢您提供的任何帮助!

【问题讨论】:

    标签: r curl oauth reddit rcurl


    【解决方案1】:

    试试这个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")
    )
    

    【讨论】:

    • 效果很好,谢谢!对于遇到此问题的任何其他人,grant_Type 中的“T”需要小写才能工作。
    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2015-05-31
    • 2020-02-28
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多