有没有办法从我的Facebook画布页面重定向到我的外部网站?我见过表格的博客和stackoverflow答案:
<script>
window.top.location = 'http://www.yoursite.com/';
</script>
Run Code Online (Sandbox Code Playgroud)
不幸的是,这些解决方案永远不会奏 我已经尝试过top.location.href,window.location和location.href ..没有用.Facebook是否通过解析这种代码来消除从javascript重定向的可能性?还有办法还是重定向吗?
更新:发生的事情是网页表现得像从未有过javascript重定向指令.事实上,当我通过firebug查看源代码时,我发现没有javascript重定向.
更新2:当我尝试window.top.location = 'http://www.yoursite.com/';上面的其他变体时,我从我的画布页面得到以下javascript错误.似乎Facebook不允许访问窗口,顶部或位置全局javascript变量:
Uncaught ReferenceError: a217374027657_location is not defined
Uncaught ReferenceError: a217374027657_window is not defined
Uncaught ReferenceError: a217374027657_top is not defined
Run Code Online (Sandbox Code Playgroud)
有趣的是,document.location = 'http://www.yoursite.com/';作品中没有例外...但当然网页不会被重定向.
更新3:想出来!Javascript重定向仅适用于iframe画布.我不得不在高级屏幕中更改我的设置以使用iframe而不是FBML.
当有人按下新的Facebook订阅按钮时,如何触发事件?我可以使用上面的代码使用"赞"按钮,所以我认为它与订阅按钮类似.
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'App_ID', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('edge.create', function(href, widget) {
alert('You just clicked the like button');
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
Run Code Online (Sandbox Code Playgroud)
当用户喜欢页面时,'edge.create'会触发事件,因此我可以获得响应,并向用户显示警报.我搜索了一会儿,用"订阅"按钮找不到类似的东西.
有没有人这样做过?
javascript facebook javascript-events subscribe facebook-javascript-sdk
我正在使用此代码在Facebook上分享图片.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<title>My Feed Dialog Page</title>
</head>
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>
<script>
FB.init({appId: "13899290", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
redirect_uri: 'YOUR URL HERE',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
} …Run Code Online (Sandbox Code Playgroud) javascript php facebook facebook-graph-api facebook-javascript-sdk
我正在尝试使用Facebook JavaScript SDK实现授权功能.当我运行它时,检查控制台我看到错误.
uncaught TypeError: Cannot read property 'userID' of undefined
Run Code Online (Sandbox Code Playgroud)
代码段
<div id="fb-root"></div>
<!-- Load the Facebook JavaScript SDK -->
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
var appId = 'APP_ID';
var uid;
// Initialize the JS SDK
FB.init({
appId: '413026618765431',
cookie: true,
});
// Get the user's UID
FB.getLoginStatus(function(response) {
uid = response.authResponse.userID ? response.authResponse.userID : null;
});
function authUser() {
FB.login(function(response) {
uid = response.authResponse.userID ? response.authResponse.userID : null;
}, {scope:'email,publish_actions'});
}
</script>
Run Code Online (Sandbox Code Playgroud) 我设法写了一个简单的小提琴,崩溃原生iOS Facebook应用程序.
如果您将此链接粘贴到时间轴http://jsfiddle.net/Gc58e/(它只是一个带有照片范围的FB.login回调的简单按钮)并从原生iOS应用程序中打开它,它将在webview中打开.
<div id="fb-root"></div>
<div class="box">
<div class="info">Let's see if we can crash it!</div>
<button class="login">Login with Facebook</button>
</div>
Run Code Online (Sandbox Code Playgroud)
window.fbAsyncInit = function () {
FB.init({
appId: '467875209900414'
});
};
(function (d) {
var js, id = 'facebook-jssdk';
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
$('.login').on('click', function () {
FB.login(function (response) {
alert('login callback' + JSON.stringify(response));
}, {
scope: 'user_photos'
});
});
Run Code Online (Sandbox Code Playgroud)
当您单击该按钮时,将显示身份验证窗口,并在单击取消 …
我正在使用phonegap插件连接到Facebook这个:https://github.com/phonegap-build/FacebookConnect
我对Facebook应用程序设置感到困惑,当我调用FB.init()时,我收到此错误消息:
Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.
Run Code Online (Sandbox Code Playgroud)
我使用Facebook登录(网站网址)编辑了网站:http:// localhost /(没有空间,我只添加了它,因为stackoverflow不允许链接'localhost'),我等了几分钟(更多)因为它工作但它仍然无法正常工作.
任何想法我怎么能让它工作?
谢谢

我创建了一个虚假的Facebook页面(娱乐页面).在附加图像的左侧,我手动创建了第一个帖子(下面的一个带有大照片)和一个以编程方式(上面带有小照片的一个).
我用于小照片的代码如下所示:
FB.api(
'https://graph.facebook.com/[myAppId]/feed',
'post',
{
message: 'this is a grumpy cat',
description: "This cat has been lost for decades now, please call at 654321486",
picture: "http://laughingsquid.com/wp-content/uploads/grumpy-cat.jpg"
},
function (response) {
if (!response) {
alert('Error occurred.');
} else if (response.error) {
document.getElementById('result').innerHTML =
'Error: ' + response.error.message;
} else {
document.getElementById('result').innerHTML =
'<a href=\"https://www.facebook.com/' + response.id + '\">' +
'Story created. ID is ' +
response.id + '</a>';
}
}
);
Run Code Online (Sandbox Code Playgroud)
但我对它并不满意:我正在制作的应用程序列出了丢失的动物,所以大照片会更大.
我没有在facebook开发者页面上看到任何如何做到这一点的例子.我相信这是可能的,但我还没有找到它.你们之前是否已经遇到过这个问题?
根据https://developers.facebook.com/docs/reference/javascript/FB.logout/
方法FB.logout()将用户注销到您的站点
这对于后来调用FB.*函数意味着什么?
具体来说,我观察到即使对FB.logout的响应状态为"未知",在注销完成后,调用FB.getLoginStatus返回状态为"connected",当传递true作为第二个参数时或之后页面刷新.
这对我来说是意料之外的......也许我误解了"将用户从您的网站中注销"的含义:这对于FB.*功能意味着什么?我希望尽可能地扭转过程FB.login.如何才能做到这一点?
更新:我在http:// localhost:8080进行测试.当http://fbtest.charemza.name/我意识到注销作品如我所料,但注销在localhost:8080注销并不会似乎工作,即表现出上述问题.要清楚,控制台中任何时候都不会出现错误.该页面的代码如下.
要稍微改变一下这个问题,为什么它会在localhost:8080上执行此操作,是否有办法在本地开发注销,其行为与公共网站上的行为相同?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Facebook Test</title>
</head>
<body>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '1524395480985654',
cookie : true,
xfbml : false,
status : false,
version : 'v2.10'
});
FB.AppEvents.logPageView();
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
document.addEventListener("DOMContentLoaded", function(event) { …Run Code Online (Sandbox Code Playgroud) 昨天,我没有这个问题.从那以后,我不相信我的任何代码都有任何变化.我得到"Polyfill JSON没有stringify的实现".FBLogin.js的第46行是FB.init.
window.fbAsyncInit = function() {
FB.init({
appId : '##########', //this is replaced with my appId
cookie : true,
xfbml : true,
version : 'v2.5'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js"; //sdk.js
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Run Code Online (Sandbox Code Playgroud) javascript facebook facebook-graph-api facebook-javascript-sdk
对于尝试在其网站中集成Facebook登录和身份验证的新开发人员,如果他们只是尝试从Facebook面向开发人员的帮助中复制教程,他们可能会收到错误.
错误是:未捕获的ReferenceError:未定义statusChangeCallback
码:
<script>
function checkLoginState() {
FB.getLoginStatus(function (response) {
statusChangeCallback(response);
});
}
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function () {
FB.init({
appId: '<Your App ID>',
cookie: true,
xfbml: true,
version: 'v2.12'
});
FB.AppEvents.logPageView();
};
</script>
<fb:login-button scope="public_profile,email"
onlogin="checkLoginState();">
</fb:login-button>
<div id="status"></div>
Run Code Online (Sandbox Code Playgroud)