【问题标题】:using cURL with Twitter API is giving me an error使用带有 Twitter API 的 cURL 给我一个错误
【发布时间】:2013-09-21 01:54:52
【问题描述】:

我设置了一个 twitter 开发帐户,并且已经用它创建了一个小应用程序。今天我尝试将 cURL 与 Twitter 的 oAuth 签名结果页面(它为你生成 cURL 命令)一起使用。

我正在尝试运行以下 GET > https://api.twitter.com/1.1/statuses/home_timeline.json

当我将其粘贴到 Twitter 以将其转换为 cURL 命令时,我得到 >

curl --get 'https://api.twitter.com/1.1/statuses/home_timeline.json' --header '授权:OAuth oauth_consumer_key="CONSUMER_KEY", oauth_nonce="OAUTH_NONCE_KEY", oauth_signature="OAUTH_SIG_KEY", oauth_signature_method="HMAC-SHA1", oauth_timestamp= "1379360432", oauth_token="OAUTH_TOKEN", oauth_version="1.0"' --verbose

当我尝试使用命令在 Windows 7 上运行 cURL 时,出现以下错误 >

* 协议 'https 在 libcurl 中不支持或禁用 * 关闭连接 -1 curl:(1)协议'https在libcurl中不受支持或禁用 * 将 URL 重建为:OAuth/ * 添加句柄:conn: 0x1dbd530 * 添加句柄:发送:0 * 添加句柄:recv: 0 * Curl_addHandleToPipeline:长度:1 * - 连接 0 (0x1dbd530) send_pipe: 1, recv_pipe: 0

随后出现更多错误..我做错了什么?

我可以成功运行以下> curl https://twitter.com/

我看到了上述命令的结果。为什么不推特--get 工作?我运行正确吗?

编辑当我删除引号并按如下方式运行时>

curl --get https://api.twitter.com/1.1/statuses/home_timeline.json --header 授权:OAuth oauth_consumer_key="KEY1", oauth_nonce="KEY2", oauth_signature="KEY3", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1379364692" , oauth_token="KEY4", oauth_version="1.0" --verbose

我走得更远..但我得到一个不同的错误>

SSL certificate verify ok.
GET /1.1/statuses/home_timeline.json HTTP/1.1
User-Agent: curl/7.32.0
Host: api.twitter.com
Accept: */*

HTTP/1.1 400 Bad Request
content-length: 61
content-type: application/json; charset=utf-8
date: Mon, 16 Sep 2013 20:54:55 UTC
Server tfe is not blacklisted
server: tfe
set-cookie: guest_id=v1%3A137936489538017864; Domain=.twitter.com; Path=/; Exp
ires=Wed, 16-Sep-2015 20:54:55 UTC
strict-transport-security: max-age=631138519

{"errors":[{"message":"Bad Authentication data","code":215}]}* Connection #0 to
host api.twitter.com left intact
Rebuilt URL to: OAuth/

有什么想法吗?

【问题讨论】:

    标签: curl twitter


    【解决方案1】:

    我找到了自己问题的答案。当你在 twitter 开发网站上使用 oAuth 工具时,你可以得到一个 cURL 命令来测试一个 API 函数。

    oAuth twitter 工具生成的代码可在 Linux 中运行,但如果您运行的是 Windows 机器,则需要将所有 '(撇号)转换为 "(引号)。我用通用“KEY”替换了我的安全令牌/密钥下面的变量来演示。

    ex) // 在 Windows 中运行

    curl --get "https://userstream.twitter.com/1.1/user.json" --header 
    "Authorization: OAuth oauth_consumer_key="KEY", oauth_nonce="KEY",
    oauth_signature="KEY", oauth_signature_method="HMAC-SHA1", 
    oauth_timestamp="1379378318", oauth_token="KEY", oauth_version="1.0"" 
    --verbose
    

    【讨论】:

    • 它正在连接到服务器。但是如何获取数据。我无法从中获取数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 2013-02-17
    • 2017-03-20
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    相关资源
    最近更新 更多