带有cURL的Xively REST API - 403 Forbidden

时间:2013-11-30 11:13:41

标签: api rest curl xively

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

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

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

cURL命令:

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"}

2 个答案:

答案 0 :(得分:1)

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

这是Xively教程中的一个疏忽,我会通知相应的人员确保它被更改。

与此同时,由于您已经创建了一个设备,因此您基本上可以在步骤3“更新源”中启动cURL教程。使用您在网站上创建的开发设备上的API密钥和Feed ID。确保将您的URL,正文以及POST请求更改为PUT请求。

答案 1 :(得分:0)

我认为您需要将您的Feed ID添加到网址的末尾。