Facebook SDK とログイン ボタンを Web ページに挿入しようとしていますが、理解できないエラーが返されます。Firefox Add-on Builder を使用しています。理想的な解決策は、コードだけでなくHTMLファイルを挿入できるようにすることですが、その方法がわかりません。の関連コードは次のとおりですmain.js
。私はそれが正しいことを知っています:
var pageMod = require("page-mod");
pageMod.PageMod({
include: "http://www.blogger.com/*",
contentScriptFile: [self.data.url("jquery-latest.js"),
self.data.url("blogger.js")]
});
そしてここにあるblogger.js
:
$('body').prepend(
'<div id="fb-root"></div>' +
'<script>' +
' window.fbAsyncInit = function() {' +
' FB.init({' +
' appId : "XXXXXXXXXXXXXXX", // App ID' +
' status : true, // check login status' +
' cookie : true, // enable cookies to allow the server to access the session' +
' xfbml : true // parse XFBML' +
' });' +
' // Additional initialization code here' +
' };' +
' // Load the SDK Asynchronously' +
' (function(d){' +
' var js, id = "facebook-jssdk", ref = d.getElementsByTagName("script")[0];' +
' if (d.getElementById(id)) {return;}' +
' js = d.createElement("script"); js.id = id; js.async = true;' +
' js.src = "//connect.facebook.net/en_US/all.js";' +
' ref.parentNode.insertBefore(js, ref);' +
' }(document));'
'$("button.blogg-button.blott-primary").click(function() {' +
' FB.login(function(response) {' +
' if (response.authResponse) {' +
' console.log("Welcome! Fetching your information.... ");' +
' FB.api("/me", function(response) {' +
' console.log("Good to see you, " + response.name + ".");' +
' });' +
' } else {' +
' console.log("User cancelled login or did not fully authorize.");' +
' }' +
' }, {scope: "publish_actions,manage_pages"});' +
'});' +
'</script>'
)
そして、これがエラーです(Firefoxエラーコンソールから):
Timestamp: 5/31/2012 8:53:28 AM
Error: An exception occurred.
Traceback (most recent call last):
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/addon-kit/lib/page-mod.js", line 195, in onRead
self._createWorker(window);
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/addon-kit/lib/page-mod.js", line 203, in _createWorke
onError: this._onUncaughtError
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/traits.js", line 110, in Trai
return self.constructor.apply(self, arguments) || self._public;
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/content/worker.js", line 403, in Worke
this._contentWorker = WorkerSandbox(this);
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/traits.js", line 110, in Trai
return self.constructor.apply(self, arguments) || self._public;
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/content/worker.js", line 202, in WorkerSandbo
this._importScripts.apply(this, contentScriptFile);
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/content/worker.js", line 260, in _importScript
load(this._sandbox, String(uri));
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/sandbox.js", line 43, in loa
return scriptLoader.loadSubScript(uri, sandbox, 'UTF-8');
SyntaxError: missing ) after argument list
編集: 行末にプラス記号を追加するのを忘れていましたが、修正しても問題は解決しませんでした。ただし、エラー コードが変更されました。
' }(document));'
' }(document));' +
新しいエラー コード:
Timestamp: 5/31/2012 9:12:06 AM
Error: An exception occurred.
Traceback (most recent call last):
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/addon-kit/lib/page-mod.js", line 195, in onRead
self._createWorker(window);
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/addon-kit/lib/page-mod.js", line 203, in _createWorke
onError: this._onUncaughtError
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/traits.js", line 110, in Trai
return self.constructor.apply(self, arguments) || self._public;
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/content/worker.js", line 403, in Worke
this._contentWorker = WorkerSandbox(this);
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/traits.js", line 110, in Trai
return self.constructor.apply(self, arguments) || self._public;
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/content/worker.js", line 202, in WorkerSandbo
this._importScripts.apply(this, contentScriptFile);
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/content/worker.js", line 260, in _importScript
load(this._sandbox, String(uri));
File "resource://jid0-nsaawinaml0b6pn0st2hc4vinxi-at-jetpack/api-utils/lib/sandbox.js", line 43, in loa
return scriptLoader.loadSubScript(uri, sandbox, 'UTF-8');
SyntaxError: missing ; before statement