0

我正在尝试遵循 xively cURL 教程。我在开发模式下创建了新设备,将默认自动生成的 API 密钥(具有 READ、WRITE、CREATE、DELETE 权限)复制到教程中的示例并获得响应:

{"title":"Forbidden","errors":"You do not have the necessary permissions to access this resource"}

我一定错过了一些明显的步骤。在脚本中使用 API 密钥之前,我是否需要以某种方式激活它?

卷曲命令:

curl --request POST \
--data '{"title":"My feed", "version":"1.0.0"}' \
--header "X-ApiKey: cPHLfGw1WJdMAbU8FzbfsdFyJ8suayHEH3OChRrkpYwQCmrb" \ 
--verbose \
https://api.xively.com/v2/feeds

完整的详细输出:

* About to connect() to api.xively.com port 443 (#0)
*   Trying 216.52.233.120...
* Connected to api.xively.com (216.52.233.120) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-RC4-SHA
* Server certificate:
*    subject: C=US; postalCode=01801; ST=MA; L=Woburn; street=First Floor; street=500 Unicorn Park Drive; O=LogMeIn Inc.; OU=Secure Link SSL Wildcard; CN=*.xively.com
*    start date: 2013-05-07 00:00:00 GMT
*    expire date: 2014-04-27 23:59:59 GMT
*    subjectAltName: api.xively.com matched
*    issuer: C=US; O=Network Solutions L.L.C.; CN=Network Solutions Certificate Authority
*    SSL certificate verify ok.
> POST /v2/feeds HTTP/1.1
> User-Agent: curl/7.29.0
> Host: api.xively.com
> Accept: */*
> X-ApiKey: cPHLfGw1WJdMAbU8FzbfsdFyJ8suayHEH3OChRrkpYwQCmrb
> Content-Length: 38
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 38 out of 38 bytes
< HTTP/1.1 403 Forbidden
< Date: Sat, 30 Nov 2013 11:03:15 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 98
< Connection: keep-alive
< X-Request-Id: 6cbb9676b448a4967187271dd246b423f7da2e39
< 
* Connection #0 to host api.xively.com left intact
{"title":"Forbidden","errors":"You do not have the necessary permissions to access this resource"}
4

2 回答 2

1

这取决于你想要做什么。任何 API 密钥都不再支持对 api.xively.com/v2/feeds 的 POST 请求。这是因为,自设备实施以来,不再支持直接以程序方式创建提要。

这是 Xively 教程中的一个疏忽,我将通知适当的人以确保它得到更改。

同时,由于您已经创建了一个设备,您基本上已经准备好在第 3 步“更新提要”处开始 cURL 教程。使用您已经在网站上创建的开发设备中的 API 密钥和 Feed ID。确保更改您的 URL、正文,并从 POST 请求更改为 PUT 请求。

于 2013-12-03T16:27:17.360 回答
0

我认为您需要将您的提要 ID 添加到 URL 的末尾。

于 2013-12-01T14:07:35.043 回答