M
Mwenge Mulenga
Hello everyone,
I'm new to ruby.I'm trying to write an application that would
synchronise with google calendar.Below is a script I'm trying to use for
authentication with google.When I try to run it I'm getting a bad file
descriptor error.I have also provided the error message just after the
script.Any help will be appriciated.Thank you in advance.
def authentication(email,passwd,service)
require 'net/https'
http = Net::HTTP.new('www.google.com', 443)
http.use_ssl = true
path = '/accounts/ClientLogin'
# Now we are passing in our actual authentication data.
data = 'accountType=HOSTED_OR_GOOGLE&Email=email &Passwd=passwd
&service=service'
# Set up a hash for the headers
headers = { 'Content-Type' => 'application/x-www-form-urlencoded'}
# Post the request and print out the response to retrieve our
authentication token
resp, data = http.post(path, data, headers)
# Strip out our actual token (Auth) and store it
cl_string = data[/Auth=(.*)/, 1]
# Build our headers hash and add the authorization token
headers["Authorization"] = "GoogleLogin auth=#{cl_string}"
end
#After calling this function like this:
authentication("(e-mail address removed)","passwd","cl")
#I get the follow error message:
Errno::EBADF: Bad file descriptor
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in `write'
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in `warn'
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in `connect'
from C:/Ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
from C:/Ruby/lib/ruby/1.8/net/http.rb:542:in `start'
from C:/Ruby/lib/ruby/1.8/net/http.rb:1035:in `request'
from C:/Ruby/lib/ruby/1.8/net/http.rb:845:in `post'
from (irb):15:in `authentication'
from (irb):23
from :0
irb(main):024:0>
I'm new to ruby.I'm trying to write an application that would
synchronise with google calendar.Below is a script I'm trying to use for
authentication with google.When I try to run it I'm getting a bad file
descriptor error.I have also provided the error message just after the
script.Any help will be appriciated.Thank you in advance.
def authentication(email,passwd,service)
require 'net/https'
http = Net::HTTP.new('www.google.com', 443)
http.use_ssl = true
path = '/accounts/ClientLogin'
# Now we are passing in our actual authentication data.
data = 'accountType=HOSTED_OR_GOOGLE&Email=email &Passwd=passwd
&service=service'
# Set up a hash for the headers
headers = { 'Content-Type' => 'application/x-www-form-urlencoded'}
# Post the request and print out the response to retrieve our
authentication token
resp, data = http.post(path, data, headers)
# Strip out our actual token (Auth) and store it
cl_string = data[/Auth=(.*)/, 1]
# Build our headers hash and add the authorization token
headers["Authorization"] = "GoogleLogin auth=#{cl_string}"
end
#After calling this function like this:
authentication("(e-mail address removed)","passwd","cl")
#I get the follow error message:
Errno::EBADF: Bad file descriptor
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in `write'
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in `warn'
from C:/Ruby/lib/ruby/1.8/net/http.rb:564:in `connect'
from C:/Ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
from C:/Ruby/lib/ruby/1.8/net/http.rb:542:in `start'
from C:/Ruby/lib/ruby/1.8/net/http.rb:1035:in `request'
from C:/Ruby/lib/ruby/1.8/net/http.rb:845:in `post'
from (irb):15:in `authentication'
from (irb):23
from :0
irb(main):024:0>