简体   繁体   中英

Attempting a PUT to Google Groups API using OAuth2 gem and Ruby

I'm trying to do a PUT call on a Google Groups API using Ruby and the OAuth2 GEM. I've managed to authenticate OK, and the GET call works properly, but I can't seem to get the call to use the PUT method. I thought the following would work, since OAuth2 uses Faraday, but I just keep getting the 400 message back, with an indication that something's "required":

data = access_token.put('https://www.googleapis.com/groups/v1/groups/{email address}?alt=json').parsed do |request|
  request.params['email'] = "{email address}"
end

Has anyone got a working example of passing parameters to a PUT request?

OK. Looks like the ".parsed" was interfering with the call here's what works, with some additions to the request object:

response = access_token.put('https://www.googleapis.com/groups/v1/groups/{email address}') do |request|
  request.headers['Content-Type'] = 'application/json'
  request.body='{"email": "{email address}"}'
end
# check this
puts response.status
# works if it's 200

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM