【问题标题】:Post to Tumblr API with R - Error "fromJSON" only for photo posts使用 R 发布到 Tumblr API - 错误“fromJSON”仅适用于照片帖子
【发布时间】:2015-03-22 12:42:59
【问题描述】:

我一直在与 R 合作,通过他们的 API 发布到 tumblr。我使用 R 包 tumblR。一切都适用于文本和链接帖子,但我在尝试发布照片时不断出错。

不知道这里有什么问题,也许是我插入照片链接的语法错误?尝试调试但无法解决。希望你们能帮助我吗?

我还发布了文本和链接帖子的代码,也许你们中的一些人自己认为这很有价值。

[R 代码]

require(tumblR)
require(httpuv)

### Authorize
consumer_key <-'key'
consumer_secret <- 'secret'
appname <- 'appname'
tokenURL <- 'http://www.tumblr.com/oauth/request_token'
accessTokenURL <- 'http://www.tumblr.com/oauth/access_token'
authorizeURL <- 'http://www.tumblr.com/oauth/authorize'

app <- oauth_app(appname, consumer_key, consumer_secret)  
endpoint <- oauth_endpoint(tokenURL, authorizeURL, accessTokenURL)
token <- oauth1.0_token(endpoint, app)
sig <- sign_oauth1.0(app, 
                     token = token$credentials$oauth_token, 
                     token_secret = token$credentials$oauth_token_secret)


### Post Text
post(base_hostname = "blogname.tumblr.com", type = "text", state = "published", tags = 'tag', 
     body = 'this is the body', token = token, consumer_key = consumer_key, consumer_secret = consumer_secret)

# => Shows: "* Hostname was NOT found in DNS cache" but posts the textpost to tumblr


### Post Link
post(base_hostname = "blogname.tumblr.com", type = "link", state = "published", tags = 'tag', url_link= 'www.somelink.de',
     title_link= 'linkTitle', description= 'this is the description', token = token, consumer_key = consumer_key, consumer_secret = consumer_secret)

# => Shows: "* Hostname was NOT found in DNS cache" but posts the linkpost to tumblr


### Post Photo
post(base_hostname = "blogname.tumblr.com", type = "photo", tags = "tag", caption_photo = 'photoTitle',
     link = "http://bilder.bild.de/fotos/bde-logo-35166394/Bild/20.bild.png",
     source_photo = "http://bilder.bild.de/fotos/bde-logo-35166394/Bild/20.bild.png", data_photo= NA,
     token = token, consumer_key = consumer_key, consumer_secret = consumer_secret)

# => Shows the following error and doese NOT (!) post the photo:

# * Hostname was NOT found in DNS cache
# *   Trying 66.6.41.23...
# * Connected to api.tumblr.com (66.6.41.23) port 80 (#0)
#   > POST /v2/blog/blogname.tumblr.com/post HTTP/1.1
#   User-Agent: RCurl
#   Host: api.tumblr.com
#   Accept: application/json
#   Authorization: ...
#   Content-Length: 490
#   Content-Type: application/x-www-form-urlencoded
#   
#   * upload completely sent off: 490 out of 490 bytes

#   < HTTP/1.1 401 Not Authorized (!!!!!!)

#   < Server: nginx
#   < Date: Sun, 22 Mar 2015 12:14:43 GMT
#   < Content-Type: application/json; charset=utf-8
#   < Transfer-Encoding: chunked
#   < Connection: close
#     * Closing connection 0

#   Warning message:
#     In if (class(token) != "Token1.0") stop("token must be a Token1.0 type") :
#     the condition has length > 1 and only the first element will be used

#   Error in fromJSON(http.connection(url, token, bodyParams, consumer_key,  : 
#                                       error in evaluating the argument 'content' in selecting a method for function 'fromJSON': Error: Not Authorized

根据我的研究,tumblr API 可能只是返回“401 Not authorized”,因为请求的语法不正确,它不必与授权(密钥、秘密等)本身相关。由于相同的凭据适用于文本和链接帖子,我认为这应该是一个不同的问题。

tumblR 描述说我们要么是“data_photo”,要么是“source_photo”,所以我猜其中一个的 NA 是可以的。反正都试过了。

感谢任何帮助,谢谢!!!

【问题讨论】:

    标签: r api social-networking tumblr


    【解决方案1】:

    tumblR 的新版本 (1.1) 已发布。

    有了这个版本:

    • ROAuth 包的依赖已被消除;
    • “照片”类型的“发布”功能已修复;
    • 关于令牌的警告消息已被删除。

    感谢您的报告!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2023-03-10
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 2014-02-16
      相关资源
      最近更新 更多