Foros del Web » Programando para Internet » Ruby »

Duda con la Gema de Twitter en ruby

Estas en el tema de Duda con la Gema de Twitter en ruby en el foro de Ruby en Foros del Web. Hola A todos tengo una duda con la gema de twitter, quiero aprender a como se utiliza para crear los post pero todavia no entiendo ...
  #1 (permalink)  
Antiguo 03/06/2015, 02:51
 
Fecha de Ingreso: junio-2015
Mensajes: 3
Antigüedad: 8 años, 9 meses
Puntos: 0
Pregunta Duda con la Gema de Twitter en ruby

Hola A todos tengo una duda con la gema de twitter, quiero aprender a como se utiliza para crear los post pero todavia no entiendo mucho la api. ya que tengo creado un scrapy en xml solo que ahora quiero enviar los datos a twitter.. :/

Nose si alguien tiene algun tutorial mas explicativo o me podrian orientas mas.. desde ya muchas gracias!
  #2 (permalink)  
Antiguo 03/06/2015, 08:24
 
Fecha de Ingreso: octubre-2013
Mensajes: 44
Antigüedad: 10 años, 4 meses
Puntos: 5
Respuesta: Duda con la Gema de Twitter en ruby

Para empezar, este tutorial está bastante bien: http://www.codecademy.com/en/tracks/twitter

Aquí el ejemplo de como enviar un tweet:

Código Ruby:
Ver original
  1. require 'rubygems'
  2. require 'oauth'
  3. require 'json'
  4.  
  5. # You will need to set your application type to
  6. # read/write on dev.twitter.com and regenerate your access
  7. # token.  Enter the new values here:
  8. consumer_key = OAuth::Consumer.new(
  9.   "CONSUMER_KEY",
  10.   "CONSUMER_SECRET")
  11. access_token = OAuth::Token.new(
  12.   "ACCESS_TOKEN",
  13.   "ACCESS_TOKEN_SECRET")
  14.  
  15. # Note that the type of request has changed to POST.
  16. # The request parameters have also moved to the body
  17. # of the request instead of being put in the URL.
  18. baseurl = "https://api.twitter.com"
  19. path    = "/1.1/statuses/update.json"
  20. address = URI("#{baseurl}#{path}")
  21. request = Net::HTTP::Post.new address.request_uri
  22. request.set_form_data(
  23.   "status" => "Hola! soy un tweet!",
  24. )
  25.  
  26. # Set up HTTP.
  27. http             = Net::HTTP.new address.host, address.port
  28. http.use_ssl     = true
  29. http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  30.  
  31. # Issue the request.
  32. request.oauth! http, consumer_key, access_token
  33. http.start
  34. response = http.request request
  35.  
  36. # Parse and print the Tweet if the response code was 200
  37. tweet = nil
  38. if response.code == '200' then
  39.   tweet = JSON.parse(response.body)
  40.   puts "Successfully sent #{tweet["text"]}"
  41. else
  42.   puts "Could not send the Tweet! " +
  43.   "Code:#{response.code} Body:#{response.body}"
  44. end

Saludos

EDITO: no me di cuenta que te referias explicitamente a la gema, en eso no te puedo ayudar
  #3 (permalink)  
Antiguo 03/06/2015, 15:17
 
Fecha de Ingreso: junio-2015
Mensajes: 3
Antigüedad: 8 años, 9 meses
Puntos: 0
Respuesta: Duda con la Gema de Twitter en ruby

Hola, Hiciste el curso completo=? lo estaba haciendo pero me quede pegado en "Reading a Tweet" 3/5

Sabes cual es el codigo real :| y el codigo que me enviaste no funciona jejejeje

aqui te mando el paso en el que estoy x.x

http://prntscr.com/7cszkb

Etiquetas: twitter
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:48.