Code Monkey home page Code Monkey logo

Comments (11)

hadley avatar hadley commented on July 26, 2024

I'd think you'd want:

  meta <- toJSON(list("title"=title, "description"=description, "type"=type))
  POST(request, config=session, body=meta, add_headers("Content-Type" = "application/json"))

from httr.

cboettig avatar cboettig commented on July 26, 2024

Ah, good idea. Unfortunately I'm getting the exact same error with this. Is there a way to see the literal POST request for debug purposes?

from httr.

hadley avatar hadley commented on July 26, 2024

The put request, you mean? Just add the verbose() config:

with_config(verbose(), figshare_create(...)

from httr.

cboettig avatar cboettig commented on July 26, 2024

hmm, I get this


< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 401 Unauthorized
< Server: nginx/0.8.54
< Date: Thu, 30 Aug 2012 16:32:53 GMT
< Content-Type: application/json; charset=UTF-8
< Connection: keep-alive
< Content-Length: 72
< 
* Connection #0 to host api.figshare.com left intact
Response [http://api.figshare.com/v1/my_data/articles]
  Status: 401
{"error": "Incorect content_type. Expected application/json, received:"} 
> 

Looks to me that it's actually the authentication that failed? ("401 Unauthorized"). The same keys work fine when I try the ruby client not sure where I have gone wrong. Thanks for the advice

from httr.

hadley avatar hadley commented on July 26, 2024

Is that the whole output? That's only what the server is sending back to you, not what you're sending to the server.

Otherwise, can you find the source code for that ruby method? It'll help to understand exactly what it's sending.

from httr.

cboettig avatar cboettig commented on July 26, 2024

I left out the top of the output that has the keys, can email that to you.

Here's the entire ruby command (keys scubbed) which works fine

require 'oauth'
require 'json'

key = "qMXXXXXXXXXXXXXXX"
secret = "zQXXXXXXXXXXXXXX"
token = "SrXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
secret_token = "yqIXXXXXXXXXX"


consumer = OAuth::Consumer.new(key, secret, {:site=>"http://api.figshare.com"})
token = { :oauth_token => token,
            :oauth_token_secret => secret_token 
        }
        client = OAuth::AccessToken.from_hash(consumer, token)

        body = JSON.generate('title'=>'Test dataset', 'description'=>'Test description', 'defined_type'=>'dataset')
        result = client.post('/v1/my_data/articles', body, {"Content-Type"=>"application/json"})

        print result.body

(from here: http://api.figshare.com/docs/demo_ruby.html#sample-code-for-ruby)

from httr.

hadley avatar hadley commented on July 26, 2024

Hmmm, that looks equivalent to your R code. Can you email me the full output?

from httr.

hadley avatar hadley commented on July 26, 2024

The problem is this line in make_request:

    config <- c(config, signed$config)

because c.config doesn't have any logic for combining headers.

from httr.

cboettig avatar cboettig commented on July 26, 2024

Nice work, thanks. Staying tuned for the update and thanks again for all the help.

from httr.

cboettig avatar cboettig commented on July 26, 2024

Any thoughts on concatenating headers?

from httr.

cboettig avatar cboettig commented on July 26, 2024

Fantastic! you rock.

from httr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.