Friday, July 27, 2012

API accesses

Its great how far technology has advanced in terms of providing access. Now-a-days one gets all the APIs to access any online application. They even document it so precisely and accurately. And if one wants a wrapper for languages like Ruby, Python, Perl and PHP then that is readily available as well.

Well I'm going to shortly discuss about some Gems I have used to access these APIs.

The first Gem that I purely awesome is the 'omniauth' Gem. It has all the routines necessary to build add-ons for other Omniauth Plugins. You might need to read more about oauth to get an idea. I managed to use the plugins - omniauth-twitteromniauth-facebookomniauth-linkedin and omniauth-instagram with this Gem. And its so easy.

You will have to add an omniauth.rb file in the initializers for starters.


Rails.application.config.middleware.use OmniAuth::Builder do 
 provider :linkedin, LINKEDIN_CONFIG['api_key'], LINKEDIN_CONFIG['secret_key']   
 provider :twitter, TWITTER_CONFIG['consumer_key'], TWITTER_CONFIG['consumer_secret'] 
 provider :facebook, FACEBOOK_CONFIG['app_id'], FACEBOOK_CONFIG['secret'], :scope => FACEBOOK_CONFIG['scope'], :display => 'popup' 
 provider :instagram, INSTAGRAM_CONFIG['client_id'], INSTAGRAM_CONFIG['client_secret'], :scope => INSTAGRAM_CONFIG['scope'] 
end


It might be a good idea to insert these configuration files on deployment, rather than put them in the git.

The you will have to call something like

current_user.services.create!(
 :provider => auth['provider'], 
 :uid => auth['uid'], 
 :token => (auth['credentials']['token'] rescue nil), 
 :secret => (auth['credentials']['secret'] rescue nil))

Better add in lots of Exception handling.

This is the authorization part. The idea is generally at the end of the authentication, you will get a token which you should use for further requests to these services. To access the data from these services, one would have to use other Gems and then pass the auth_token (and auth_secret).

The gems used to access the data are :
fb_graph Gem for Facebook
twitter Gem for Twitter
linkedin Gem for Linked In
instagram Gem for Instagram

Try them out. You will love them.

Monday, July 9, 2012

The QR Hacker is a great tool ! I created mine here ..


Monday, July 2, 2012

FB Tab

My Father-in-law has this page on Facebook which is related to Astrology. He does a lot of work after his normal work to get stuff published to the site and let users have a good time reading the topics. He even answers them by email. Anyway, he wanted something set up on Facebook as a page and he sought my help. 

I wanted to test this out myself, so I thought I should see how it is done. I ultimately went on to use a third party app which did the page/tab creation. I was not happy with myself.

The previous week I had to do a similar thing and this time I had more resources to work with. These are some of my observations and pointers to set up a simple tab in FB.

The tab setup is not straightforward in FB. 

1. You will have to create an application which has the url (secure and non-secure) filled out. Make sure you select the 'Page Tab' option, fill in the Urls. Also remember to fill in the url in the Site URL field as well. 

2. Remember that your page should have a maximum width of 810px. The default width is 520px (I used 810px)

3. The height adjusts with itself. So I don't think you will have to worry about that.

4. Use this url to add the created application as a tab to your page 

http://www.facebook.com/dialog/pagetab?app_id=APP_ID&next=URL

I would suggest to use URL as http://www.facebook.com

5. Facebook posts a signed token to the URL you specified in the url field. It tries to use the non-secure one by default, but uses the secure one if FB was open as a secure connection.

6. Be careful if you intend to host the html file (end point HTML) in S3. Won't work. Simply because S3 treats POST requests as file uploads and gives out errors. As Facebook makes a POST request to the S3 URL you gave, you would probably see an unauthenticated message on the UI.

7. Better set up a server for the HTML and then add all the S3 stuff inside that !

That is pretty much it !