I've got a Rails app in which I'm building an interface for a user to send a tweet with text, a link, and/or an image. I'm trying to figure out how to handle parsing links into a t.co format and what to do with usernames, but I'm coming up short on any clear explanation of what's required.
I'm using the twitter and omniauth-twitter gems and I've also found the twitter-text gem. What I need to know is, am I required to parse links into a t.co format or do anything to usernames in my app before posting to the API? If so, how can I do that in Ruby/Rails? The documentation for the twitter-text gem, which seems to be the official way to handle this function, is nonexistent.
Thanks!
Related
I'm Ruby n00b, so please excuse my first question.
I've got my Rails environment up on a web server up, and now I am trying to find a Ruby functions (methods?) that would allow me to do the following:
Function 1
suck in an XML feed from another website
cherry pick a particular field from that XML field (e.g. email addr or phone)
Function 2
send that particular XML field to phone number via Twilio.
Any suggestions on where to start would be helpful. (Even if it's to tell me to RTFM)
For your first function, you don't need to do anything with Twilio. I presume you want to parse an XML feed to get specific data from it.
You can use a gem like nokogiri to parse XML, have a look at this similar SO question to learn how:
Parsing XML with Ruby
There's tons of other resources on parsing XML using ruby here to:
https://www.google.ca/search?q=parse+xml+ruby&rlz=1C1CHFX_enCA552CA552&oq=parse+xml+ruby&aqs=chrome..69i57j0l5.3359j0j7&sourceid=chrome&es_sm=122&ie=UTF-8
For your second function, this is where you'll actually be using Twilio. First off, I'm assuming you've setup Twilio, if not, head over to and sign up:
https://www.twilio.com/
You'll want to add the Twilio ruby client in your Gemfile:
gem 'twilio-ruby'
Be sure to bundle install and if everything is good, you are ready to code your Twilio interaction. Assuming from fn1 you have the data in a variable, you'll now need to send it via SMS/MMS, here's the Twilio guide for that:
https://www.twilio.com/docs/quickstart/ruby/sms/sending-via-rest
Integrating facebook,twitter and google plus into another web app, so that the posts in that app are posted write away as status in facebook,tweets in twitter and status in google plus.I am developing this using ruby on rails.I searched a lot about this but didn't find anything which would work for me.Can post some links or ideas which would be helpful for this.
For Facebook I must suggest you to use Koala Gem...
For Twitter
Twitter
https://twitter.com/about/resources/buttons
A twitter button can be easily generated here and placed on your web site..Its working great. You can even customize everything in twitter.. Its so user friendly.
For Google plus
Google Plus
I am just working on Google plus..Facing some difficulties as its having so many restrictions.
Still I would Like to Share a link you can follow that..
How to share content from our site to google plus
I hope it will work fine...
I'd suggest to use Koala ( https://github.com/arsduo/koala/wiki ) to interface with Facebook. It's by far the best maintained fb library out there.
Otherwise, you should learn one thing or two about OAuth2:
https://github.com/intridea/oauth2
https://developers.facebook.com/docs/authentication/
https://developers.google.com/accounts/docs/OAuth2
Use https://github.com/sferik/twitter to interact with twitter.
For google, I've found that implementing the XML chat manually is easier than using any existing API wrapper. To convert XML responses into data, you an use a combination of the Response#parsed method of oauth2 gem and Array.wrap of ActiveSupport (there is no way for an XML parser to tell a single node to a possibly repeated node (so an array) that appears just once, avery big drawback of XML in my point of view)
Or you can directly ask google for JSON, so you already have the data correctly structured.
And, as #brendan-benson very correctly says, do only API calls in background workers, never in your normal request/responses cycle.
There are plenty of gems available to access these APIs:
Twitter API Wrapper
Facebook API Wrapper
Google Plus API Wrapper
Since APIs are flaky, it's best to use a queueing system like resque to queue the calls in Post#after_create, and then have a resque worker execute the call asynchronously.
When using FB or Google + I can paste a link of any website into the status update box and it will instant load information about that website with the option of flicking through thumbnail images.
How can I go about achieving this in ruby on rails? All my searches seem to bring up php methods on how to do this.
For grabbing video data info I use the Ruby Open Graph Protocol gem. Is there any thing for grabbing data the way FB and G+ do? If not is there a standard way this is done in rails/ruby, if so.. how is this done?
Kind regards
I think you're looking for something like oembed. I've found a gems for that, so I propose you to take look at it: https://github.com/judofyr/ruby-oembed or https://github.com/embedly/embedly-ruby
You should likely use a gem like http://nokogiri.org/
It allows you to work with a html page just as you would do with jQuery. Very handy.
I'm working on a rails app that searches the Twitter API stream for keywords and then records those tweets.
I've used Hpricot before to parse XML but I was wondering if someone could recommend a gem (or even a best practice) to parse JSON from the Twitter search API?
If you use the newly rewritten Twitter gem, you can make a query like this:
Twitter.user_timeline("sferik").first
The response would be a Hashie::Mash object corresponding to the first status. To access the information, you just call the attribute like it was a method:
Twitter.user_timeline("sferik").first.text
The response from this is just text. You don't have to directly deal with JSON.
I believe there are many twitter gems that should work. Github has the twitter gem as the most popular.
I have used it 1 1/2 yrs ago, but it should do what you want and have support to back it up.
I use the json gem to parse Twitter responses. To access the api I use grackle and sometimes curb to do api requests in parallel (Curl::Multi).
There is code to use Facebooker gem (which uses the old Facebook REST API). Does someone have experience how to convert those code to
using Facebooker2, which uses the new Facebook Graph API?
For example, Facebooker has Facebooker::Session and Facebooker::User and they are both gone in Facebooker2.
I can't find too much docs on the two sets of API.
I've written an article about converting your Facebooker app to Facebooker2. This also means that should change from FBML to iFrame if you haven't already:
http://www.clickonchris.com/2010/11/facebooker-converting-from-fbml-to-iframe/