0

I am trying to use Facebook API for likes on my web page. Currently trying to use all.js, it fails to load the file at url below as it translates it to file://connect.

//connect.facebook.net/en_US/all.js#xfbml=1

Changing url explicitly to http: gives a different error.

Do we need APPID for initializing this API and use all.js or can it be used without APPID?

Reference URL: http://developers.facebook.com/docs/reference/plugins/like/

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Sumit B
  • 300
  • 4
  • 11

1 Answers1

3

According to this answer, an AppId is required. The tool in the reference URL you listed will insert your AppId in the code it generates.

(function(d, s, id) {
    ...
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxxxxxxx";
    ...
}(document, 'script', 'facebook-jssdk'));

You are probably getting the file://connect error because you are testing by opening a local file in your web browser instead of a file served by a real web server. When you don't specify the protocol in a link, the browser will assume it's the same protocol as the current page.

From the Facebook documentation:

Note: The URLs in the code are protocol relative. This lets the browser load the SDK over the same protocol (HTTP or HTTPS) as the containing page, which will prevent "Insecure Content" warnings. Missing http and https in the code is intentional.

Community
  • 1
  • 1
Mike Valenty
  • 8,941
  • 2
  • 30
  • 32
  • Thanks a bunch! This insight into relative protocol, is really helpful. I will fix it accordingly, but isn't URL to page enough for getting 'like' to work. Iframe works without APPID, could you confirm 'again', if there is no escape from APPID, for using ALL.JS. – Sumit B Nov 06 '12 at 18:09
  • According to another SO answer, it's required: http://stackoverflow.com/questions/5574443/do-i-need-an-appid-for-a-xfbml-version-of-the-facebook-like-button – Mike Valenty Nov 06 '12 at 22:22
  • I have no APPID and switching sdk.js to all.js in the FB post embed code makes the embeds work when they dont' with sdk.js. – jerclarke Apr 09 '15 at 16:16