Getting error with a HTTP Post request?

两盒软妹~` 提交于 2020-01-07 04:22:33

问题


I am trying create a new share link for onedrive file access.

This is what I am supposed to do,

POST /drive/items/{item-id}/action.createLink
Content-Type: application/json

{
"type": "view"
}

I have created a post request in ruby as follow,

require 'net/http'
require 'json'

uri = URI.parse("https://api.onedrive.com/v1.0")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Post.new("https://api.onedrive.com/v1.0/drive/items/file.88e469b2d4c51142.88E469B2D4C51142!113/action.createLink")
req.content_type = "application/json"   
json = {:type=> "view"}.to_json   
req.body = json
response = http.request(req)
puts response.body
puts response

By running the above code I am getting the following error as JSON,

{
"error": {
"code": "invalidArgument",
"message": "ObjectHandle is Invalid",
"innererror": {
  "code": "badArgument",
  "innererror": {
    "code": "invalidObjectHandle",
    "innererror": {
      "code": "invalidResourceId"
    }
  }
}
}
}

My first impression is that I am setting the request.body with a wrong value of JSON how to overcome this error?


回答1:


The id you provided (file.88e469b2d4c51142.88E469B2D4C51142!113) is not a valid id for this API. It looks suspiciously like one obtained from the LiveConnect API, and those aren't compatible with this new API. If you obtain the id using the new api and use that with your same query it should work.



来源:https://stackoverflow.com/questions/29737828/getting-error-with-a-http-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!