在FB.init之后立即调用时,FB.api不起作用.这是我使用的代码片段:
window.fbAsyncInit = function() {
FB.init({
appId : window.APP_ID,
status : true,
cookie : true,
oauth : true,
channelUrl : window.MASTER_URL + "channel",
frictionlessRequests : true
});
window.COMPANY.init();
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
Run Code Online (Sandbox Code Playgroud)
这是我的COMPANY.init()和COMPANY.fetchAllFriends():
friends: new Array(),
init : function() {
// TODO
COMPANY.fetchAllFriends();
FB.Canvas.setSize($(document).height());
FB.Canvas.setAutoGrow();
},
fetchAllFriends : function() {
FB.api('/me/friends', function(response) {
if (!response || response.error) {
return;
}
COMPANY.friends = new Array();
$.each(response.data, function(index, value) …Run Code Online (Sandbox Code Playgroud) 如果我登录到facebook.com,我希望调用FB.getLoginStatus将返回status ='not_authorized'.相反,它返回status ='unknown',即使我为'force'参数传递true也是如此.
如果我调用FB.login,然后调用FB.getLoginStatus,我得到status ='connected'.说得通.
如果我调用FB.login,重新加载页面,然后调用FB.getLoginStatus,我得到status ='unknown'.没有意义.如果我添加'true'作为第二个参数(即力),我仍然得到status ='unknown'.(在这种情况下,我希望status ='not_authorized'.)
似乎没有办法在实践中获得status ='not_authorized'.
难道我做错了什么?这是FB.getLoginStatus或其文档中的错误吗?
这是一个最小的测试页面:http: //pastebin.com/NqiBXni2
语境:
我正在编写一个网站小部件,显示公共Facebook页面的帖子.(这可以在不通过app访问令牌提示用户的情况下访问.)每个帖子都有一个"赞"/"不同"链接.为了确定是否显示"喜欢"或"不喜欢",我需要知道浏览用户的Facebook ID是什么,以便我可以检查它是否在帖子的喜欢列表中.
这似乎在我没有任何改变的情况下发生.突然之间,除Chrome之外的任何浏览器都没有处理fb:login-button标签,它只是将标签中的任何文本显示为纯文本.
在网上搜寻几个小时,寻找可能的原因/解决方案后,我发现没有任何解决这种特殊行为的方法.
所以,我已经创建了最基本的例子来说明问题,并把它放在这里:http: //silverbucket.net/examples/fblogin/welcome.htm
上面的示例显示了Chrome中的fb-login框,但不包括Firefox,IE或Opera.
总结一下,上面链接页面中的内容,首先是顶部的html标签:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/" lang="en">
Run Code Online (Sandbox Code Playgroud)
在我的头脑中:
<script src="http://connect.facebook.net/en_US/all.js"></script>
Run Code Online (Sandbox Code Playgroud)
在身体中,我的头部正下方:
<div id="fb-root"></div>
Run Code Online (Sandbox Code Playgroud)
然后是实际的fb-login-button:
<fb:login-button scope="email, user_interests, user_likes, publish_stream">log in with facebook</fb:login-button>
Run Code Online (Sandbox Code Playgroud)
而且,在页面底部,就在关闭body标签之前,我有FB JavaScript:
<script>
$(document).ready(function() {
window.fbAsyncInit = function() {
FB.init({
appId : '153787078069017',
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
//channelUrl : '/channel.html', // channel.html file
oauth : true, // enable OAuth 2.0
status : false
});
// …Run Code Online (Sandbox Code Playgroud) 如果用户登录到 facebook,FB.getLoginStatus() 工作正常。但是,如果用户未登录 facebook,则不会调用 FB.getLoginStatus() 回调,并且我无法在我的代码中处理这种情况,因为我没有收到回调。我不是在沙盒模式。
我还添加了 'true' 来强制回调 eg) FB.getLoginStatus(function(response){}, true)。它没有帮助。这是一个错误吗?已经修好了吗?
如果没有,请在用户退出 Facebook 时解决。我现在在这个问题上坚持了一个星期。
function GetFBLoginStatus() {
FB.getLoginStatus(function(response) {
alert("inside call back function");
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
alert("Connected FBID = " + uid);
} else if (response.status === 'not_authorized') {
alert("not_authorized");
} else {
alert("Not Logged into facebook");
}
return true;
}, true)
}
Run Code Online (Sandbox Code Playgroud) authorization facebook facebook-javascript-sdk facebook-login
我们已经让Facebook在我们的主桌面应用程序上运行而没有任何问题.当我向移动网站添加相同的设置代码时,我收到了来自JavaScript SDK的错误:
Received message of type object from https://s-static.ak.facebook.com, expected a string
然后,我从此处将设置代码更改为完全复制:https://developers.facebook.com/docs/guides/mobile/web/并收到完全相同的消息.
此错误仅在Chrome开发者工具或iOS模拟器中用户代理为iOS或Android时显示.当它从桌面运行时,我们没有看到此错误.
知道这里发生了什么吗?
谢谢 :)
我已经设法在Facebook上按照此处的文档为我的应用程序实现"发送请求"功能
现在,如果用户'A'接受用户'B'发送给他的请求,我希望用户'B'获得特定于应用的礼物(图像).我的问题是,我怎么会发现是用户'B'邀请了用户'A'?(而不是用户'C')
谢谢.
这似乎是一个简单的问题,其他人已发布,但答案仍然没有找到我.具体来说,我已经反复通过这两个(这里和这里)SO问题,我只是没有与我的情况联系.
对我来说,我以为我会在div中包含登录按钮,然后根据登录状态更改div可见性.div确实改变了可见性,但fb登录按钮仍然可见???
这是我在div中包装登录按钮的代码:
....snip....
<div id="fblogin">
<table align="center" style="text-align:center;">
<tr>........</tr>
<tr>
<td>
<div id="fb-root"></div>
<span id="fb-login">
<div
class="fb-login-button"
onlogin="afterFbLogin()"
data-show-faces="false"
data-width="200"
data-max-rows="1"
data-scope="publish_stream">
</div>
</span>
............snip.............
Run Code Online (Sandbox Code Playgroud)
这是我的FB.Init并检查登录状态:
window.fbAsyncInit = function () {
FB.init({
appId: '352810974851050', // App ID
channelUrl: '//www.domain.com/channel.html',
status: true, // check login status
cookie: true, // enable cookies
xfbml: true // parse page for xfbml or html5 like login button below
});
// Put additional init code here
FB.getLoginStatus(function (response) {
if (response.status …Run Code Online (Sandbox Code Playgroud) 我正在努力通过FB.login检索电子邮件.这是我的代码如下:
$(document).ready(function() {
$.ajaxSetup({ cache: true });
$.getScript('//connect.facebook.net/en_US/all.js', function(){
FB.init({
appId: 'appId',
cookie: true,
oauth: true
});
$('#fbRegister').on('click', function(){
FB.login(function(response){
if(response.authResponse)
{
FB.api('/me?fields=email,name', function(responseFromFB){
var name = responseFromFB.name;
var email = responseFromFB.email;
//Take the vales and send to
$.ajax({
type: "POST",
url: 'php/register.php',
async: false,
data: {'name':name,'email': email},
success: function(data)
{
$('#fbRegister').hide();
$('#successPrompt').show().text(data);
},
complete: function() {},
error: function(xhr, textStatus, errorThrown)
{
console.log('ajax loading error...');
return false;
}
});
},{scope:'email,name'});
}
else
{
console.log('The login failed because they were already …Run Code Online (Sandbox Code Playgroud) 我想添加一个非常基本的Facebook分享按钮,如下所示:
https://developers.facebook.com/docs/plugins/share-button?locale=fr_FR
问题是按钮不会简单地显示,没有javascript或网络错误.
谁能说我做错了什么?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>titre</title>
</head>
<body>
<div id="fb-root"></div>
<script>(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/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助
当一个函数被点击Facebook分享按钮时,我的Facebook共享窗口出现了.
问题是Facebook窗口试图出现但被弹出窗口拦截器阻止.
这是我第一次创建共享窗口.是否有一个绕过弹出窗口阻止程序的简单解决方案?
这是触发该功能的按钮:
<button class="share-now" onclick="fb_callout();">
Run Code Online (Sandbox Code Playgroud)
以下是调用的函数:
<script>
function fb_callout() {
(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));
}
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '162280254223002', // App ID from the App Dashboard
xfbml : true,
version : 'v2.5',
status : true
});
// Additional initialization code such as adding Event Listeners …Run Code Online (Sandbox Code Playgroud) javascript facebook facebook-graph-api facebook-javascript-sdk