【问题标题】:Post photo to Twitter using Curl and Windows command line使用 Curl 和 Windows 命令行将照片发布到 Twitter
【发布时间】:2020-01-29 09:32:12
【问题描述】:

我正在使用 Curl 通过 Windows 命令行发布到 Twitter API。我已经生成了 oAuth 标头,并且可以使用以下方式发布没有照片的推文:

curl -k -X POST "https://api.twitter.com/1.1/statuses/update.json" -d "status=Test" -H "Authorization: OAuth oauth_consumer_key=\"xxxxxxxxxxxxxxxxxxx\", oauth_nonce=\"xxxxxxxxxxxxxxxxxxxxxxx\", oauth_signature=\"xxxxxxxxxxxxxxxxxxx\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"xxxxxxxxxx\", oauth_token=\"xxxxxxxxxxxxxxxxx\", oauth_version=\"1.0\""

这可以很好地发布状态,但我似乎无法弄清楚如何使用 statuses/update_with_media 端点发布具有状态的照片。我知道这个端点已经贬值了,但我暂时想用它。

我尝试了一些变体:

curl  -k -X POST "https://api.twitter.com/1.1/statuses/update_with_media.json" -F \"[media]=@photo.jpg\" -F \"status=Test\" -H "Authorization: OAuth oauth_consumer_key=\"xxxxxxxxxx\", oauth_nonce=\"xxxxxxxxxxxxxxx\", oauth_signature=\"xxxxxxxxxxxxxxxx\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"xxxxxxx\", oauth_token=\"248911615-xxxxxxxxxxx\", oauth_version=\"1.0\""

没有运气。我总是收到 {"code":195,"message":"Missing or invalid url parameter."} 错误或 {"code":32,"message":"Could not authenticate you."}。

我似乎无法找出正确的语法和签名来发布状态和照片。

如果更容易的话,我很乐意使用更新的媒体/上传方法,但我也无法使用它。

【问题讨论】:

  • 我强烈建议您不要使用update_with_media,因为它已经过时了。有示例 herehere 演示了使用 twurl 的 media/upload 方法。使用 curl,当包含您的媒体时,您可能无法正确生成签名。
  • 不幸的是,我无法使用 twurl,因为我无法安装 Ruby。我需要它通过 shell 命令通过 curl.exe 运行。但我会检查这些示例,看看是否能得到任何提示。

标签: curl twitter command-line twitter-oauth


【解决方案1】:

我想出了让更新的媒体/上传端点工作的语法和签名:

curl -k -X POST "https://upload.twitter.com/1.1/media/upload.json" -F "media=@file.jpg" -H "授权:OAuth oauth_consumer_key=\"xxxxxxxxxxxxxxx\", oauth_nonce=\"xxxxxxxxxxxxx\", oauth_signature=\" xxxxxxxxxxx\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"xxxxx\", oauth_token=\"xxxxxxxxxxx\", oauth_version=\"1.0\""

密钥不包括媒体文件作为签名的一部分

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2018-03-18
    • 1970-01-01
    • 2011-07-26
    • 1970-01-01
    • 2017-03-31
    相关资源
    最近更新 更多