这是我的代码,但不起作用:
FB.api(
{
method: 'fql.query',
query: 'SELECT uid, first_name, last_name FROM user WHERE uid=100002306311953'
},
function(data) {
alert(data.uid);
}
);
});
Run Code Online (Sandbox Code Playgroud)
我在警报中得到"未定义".为什么?
嗨,我在网上使用Facebook按钮.我的所有内容都是通过ajax加载的,我已经知道如果你想使用带有ajax加载内容的facebook这样的按钮你应该使用FB.XFBML.parse().我已经使用过它并且运行良好是firefox和chrome但它在IE中不起作用.我正在检查IE 8.我搜索了解决方案,发现在这里添加xmlns:fb="http://www.facebook.com/2008/fbml"我的html标签.我做了但是还没修好.我的代码看起来像
layout.php
<div id="fb-root" style="display:none"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APPID', // 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
};
(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_GB/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, …Run Code Online (Sandbox Code Playgroud) 我正试图通过JavaScript和Graph API从facebook上获取专辑列表.我是这样做的:
FB.api('/me/albums', function(response){
//
});
Run Code Online (Sandbox Code Playgroud)
专辑封面作为照片ID返回,而不是我可以插入到HTML中的网址.所以,我需要在第二步获得一个网址.但是,通过应用程序设计,我以后无法获取URL并插入图像.我需要返回一个包含album propereties(id,name,cover url)的完整数据对象.我的最后一次尝试如下:
FB.api('/me/albums', { fields : 'id,name,count,cover_photo' }, function(response){
if (!response || response.error) {
callback.call(false);
return;
};
var parsed = $(response.data).map(function(){
if (this.count > 0) {
var result = {
aid : this.id,
title : this.name,
cover : this.cover_photo
};
return result;
};
});
for (var i = 0; i < parsed.length; i++) {
(function(i){
FB.api('/' + parsed[i].cover, { type : 'album' }, function(response){
parsed[i].thumb = response.picture;
});
})(i);
};
callback.call(parsed);
});
Run Code Online (Sandbox Code Playgroud)
问题是循环不等待封面查询和前进,留下返回对象没有封面网址.我认为做起来并不困难,但我找不到足够长的解决方案.欢迎任何想法.
javascript asynccallback facebook-graph-api facebook-javascript-sdk
我使用以下代码发布到用户wall.I从developer.facebook获取此代码.但是在打开对话框时会出现"发生错误.请稍后再试"等错误.
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'http://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications"
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
Run Code Online (Sandbox Code Playgroud)
请分享想法来解决这个问题
我正在构建一个聚合Wordpress网站中其他页面的页面,并显示有关它们的信息片段以及"赞"按钮.现在我正在使用iFrame选项.
当用户点击视频时,会将其显示在包含视频,某些文字和"赞"按钮的"功能"区域中.此HTML是从模板生成的,并在用户点击视频观看后创建.没有页面刷新.
如果我使用Like按钮的HTML5版本,它永远不会被渲染,我猜测是因为在调用Facebook初始化时,Like div永远不存在.我不想使用iFrame版本,因为它似乎不允许我让人们评论他们的喜欢.
有没有办法让Facebook重新扫描要渲染的元素?我知道Twitter会允许你通过twttr.widgets.load()随时运行来重新扫描要呈现的内容来实现这一点.
所以我使用2.3 API版本尝试访问/ me/friends列表,该列表返回我所有使用该应用程序的朋友.除此之外,它总是返回以下内容:
{
"data": [
],
"summary": {
"total_count": 889
}
}
Run Code Online (Sandbox Code Playgroud)
我已尝试在浏览器中使用Graph Explorer和JS Sdk,但没有运气.
我正在请求user_friends权限,默认情况下它实际上包含在内.是的,我有很多朋友一直在使用我们的应用程序.我通过Facebook的调试器在线调试令牌,并得出结论,令牌确实具有该权限.
注意:我们的应用程序未列在Facebook应用商店中.然而,它可以直播并向公众开放.
有人可以帮忙吗?
如何在运行时更改fb-video的视频URL,并让播放器重新加载视频而不刷新页面:
<div id="fb-root" style="height: auto"></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 = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-video"
data-href="https://www.facebook.com/abcxyz/videos/vb.123/123/?type=1"
data-allowfullscreen="true"></div>
Run Code Online (Sandbox Code Playgroud)
这就是我现在在HTML中的代码,它在页面加载时起作用.我现在只想知道是否有可能以某种方式更改数据-href,然后让Facebook嵌入式视频播放器指向新视频.
我想创建一个Facebook登录按钮。确实我做了,但是我需要获取用户名,电子邮件和其他信息。我怎样才能做到这一点?
这是我的代码
<html>
<head></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/tr_TR/sdk.js#xfbml=1&version=v2.4&appId=168750412481****";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-login-button" data-max-rows="1" data-size="large" data-show-faces="false" data-auto-logout-link="true" data-scope="email"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如何获得数据范围用户的电子邮件或其他范围属性?
我决定将FB登录/共享功能集成到我的网站.但是,我无法使简单的脚本工作,因为我得到http // https协议错误:
Uncaught SecurityError: Blocked a frame with origin "https://staticxx.facebook.com" from accessing a frame with origin "http://www.my-site.com". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.
Run Code Online (Sandbox Code Playgroud)
我从FB文档复制粘贴的代码是:
<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/sdk.js#xfbml=1&version=v2.5&appId=505598882820893";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
Run Code Online (Sandbox Code Playgroud)
实际上,当我运行登录脚本时,我得到了同样的错误. …
我目前正在开发一个使用Facebook Graph API的网络应用程序.
我想要实现的是获取用户的所有帖子.
但是,这并不容易,因为我必须对结果进行分页.
目前,我正在兑现承诺.
我试图实现的是用post对象填充数组.
因此,我使用的promises和递归不能按预期工作.
我的代码目前看起来如下:
// Here I retrieve the user with his or her posts,
// just the first 25 due to pagination
if (accessToken) {
return new Promise(resolve => {
FB.api('/me?fields=id,name,posts&access_token=' + accessToken, response => {
this.get('currentUser').set('content', response);
resolve()
})
})
}
// Returns all posts of a given user
function getAllPostsOfUser(posts, postsArr) {
// Process each post of the current pagination level
for (var post of posts.data) {
// Only store meaningful posts …Run Code Online (Sandbox Code Playgroud) javascript recursion facebook-graph-api facebook-javascript-sdk es6-promise