Posts Tagged ‘ facebook ’

OmniAuth facebook/twiitter SSL certificate error

i have used Omniauth for facebook login . I followed this tutorial to integrate facebook login

I followed all the steps of that tutorial but after authorizing the app and when redirect to /auth/facebook/callback fails with:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

This error we get because Omniauth/Oauth wasn’t setting the ca_path variable for OpenSSL of their HTTP calls.OpenSSL did not find the root certificate for Facebook’s SSL certificate.As a result we got this error.

We can solve the issue by two ways .

  • One way is we can set SSL certificate path
  • anothe one is ignore the certificaiton verification

Let’s see what will we do if we want to ignore the certification:

  • you can fix this in CBA’s application-config.
  • Add the following line to your file config/omniauth.rb

So now config/omniauth.rb will be look like :

Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, "apikey", "secretkey"

what will we do to set the certification path :

take a look at this link ruby on rails and ssl error

    • sudo port install curl-ca-bundle
    • modify the config/omniauth.rb files
    • set ca_path in the client options
    • Rails.application.config.middleware.use OmniAuth::Builder do :
      facebook, FACEBOOK_KEY, FACEBOOK_SECRET, {:client_options => {:ssl => {:ca_path => "/opt/local/share/curl/curl-ca-bundle.crt"}}}

Hopefully this two ways can be solved the SSL certificate issue.


AJAX In Facebook

Now days Ajax is doing a very important rule .That’s in the face book application , it also very necessary .

In this section I will describe the ajax method for facebook application.

I assume that the rader will have an idea about the ajax and some idea of FBJS.

First I focus the categories of ajax method in facebook.

There are different ways you can perform ajax in facebook.

1. MOCK Ajax .(

2. TypeHead Ajax. ( )

3. Using FBJS/ AJAX ( )

I feel comfort for the last one, because it quite similar with jquery. ( ).

Also “FBJS is Face book’s solution for developers who want to use JavaScript in their Facebook applications. We built FBJS to empower developers with all the functionality they need, and to protect our user’s privacy at the same”

So let’s start with the FBJS/ AJAX

At first see the features of AJAX.

1. FBJS supplies a very powerful AJAX object

2. It supports retrieving JSON, FBML, or raw text from remote servers.

3. To use it, just instantiate a new Ajax class.

4. It has an event handler which fires when an AJAX call returns

5. It has an event handler which fires when an error occurs during an AJAX call

6. It can check whether user login.

7. Data send through post.

Now we look at the AJAX Method:


This can be Ajax.RAW, Ajax.JSON, or Ajax.FBML.


The response from your server will be returned to your callback in its original form.


The response from your server will be parsed as a JSON object and returned to your callback in the form of an object. Properties of your JSON object which are prefixed with “fbml_” will be parsed as individual FBML strings and returned as FBML blocks. These blocks can used on a DOM object with the setInnerFBML method.


The response from your server will be parsed as FBML and returned as an FBML block. This block can used on a DOM object with the setInnerFBML method.


An event handler which fires when an AJAX call returns.


An event handler which fires when an error occurs during an AJAX call


If you set this to true the AJAX call will require the user to be logged into your application before the AJAX call will go through. The AJAX call will then be made with the regular fb_sig parameters containing the user’s identity. If they refuse to login, the AJAX call will fail.

post ( url, query)

Start an AJAX post. url must be a remote address, and query can be either a string or an object which will be automatically converted to a string.

Note: be careful about the url. Use the callback url . Do not write facebook url. Like ()

Like use this :

not to use :

Now we start through step by step :

1. Create an instance of AJAX class. Like : var ajax = new Ajax();

2. Set the response type of ajax.

Like: if you use FBML then use

ajax.responseType = Ajax.FBML;

3. Set the require login. like : ajax.requireLogin = true;

4. Now you write the function that will handle the event after success of ajax call.

Like :

ajax.ondone = function (data) {

document.getElementById (‘message’).setInnerFBML(data);


Note: here data is the result of Ajax.

5. You can also set onerror for handling the error.

6. Call the url through post method .Like

var params={“user”:user_id,”video_id”:video_id}; //add parameters as comma separated “param”:value‘callbackurl not facebook url l,params);

Well you see here you can see that post method has two parameter. post callbackurl,parameter);

There is useful links from where you can get the full example of ajax .