使用Curl和Windows命令行将照片发布到Twitter [英] Post photo to Twitter using Curl and Windows command line

查看:64
本文介绍了使用Curl和Windows命令行将照片发布到Twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Curl通过Windows命令行发布到Twitter API.我已经生成了oAuth标头,可以使用以下方法发布不带照片的推文:

I am using Curl to post to the Twitter API via the Windows command line. I've already generated the oAuth headers and can post a tweet without a photo using:

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端点发布具有状态的照片.我知道此端点已贬值,但我想暂时使用它.

This works fine to post a status, but I can't seem to figure out how to post a photo with a status using the statuses/update_with_media endpoint. I know this endpoint is depreciated, but I want to use it for the time being.

我尝试了以下几种变化:

I've tried some variations of:

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":缺少或无效的url参数."}错误或{"code":32,"message":无法对您进行身份验证."}.

with no luck. I always get a {"code":195,"message":"Missing or invalid url parameter."} error or {"code":32,"message":"Could not authenticate you."}.

我似乎无法弄清楚发布状态和照片的正确语法和签名.

I can't seem to figure out the right syntax and signature to post both a status and a photo.

如果很容易,我很乐意使用更新的媒体/上传方法,但是我也无法使它正常工作.

I'd be happy to use the newer media/upload method if that's easier, but I haven't been able to get that working either.

推荐答案

我弄清楚了使新的媒体/上传端点正常工作的语法和签名:

I figured out the syntax and signature to get the newer media/upload endpoint to work:

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

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

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

The key is not including the media file as part of the signature

这篇关于使用Curl和Windows命令行将照片发布到Twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆