我正在成功显示邀请朋友对话框(代码如下所示).当用户点击跳过时,iframe /对话框会显示新页面.但是从这一点来说,我找不到如何关闭iframe /对话框的方法.FB.ui不返回任何对象,似乎没有Javascript SDK方法,并且使用DOM遍历和操作将对任何FB代码更改都很脆弱.
有任何想法吗?
function popupInviteForm(actionUrl) {
var fbmlString = '<fb:fbml>' +
' <fb:request-form type="POST" content="Play against me in game?" action="' + actionUrl + '" method="post" >' +
' <fb:multi-friend-selector target="_self" exclude_ids="" max="20" cols="4" rows="3" showborder="false" actiontext="Invite friends!" />' +
' </fb:request-form>' +
'</fb:fbml>';
FB.ui({
method: 'fbml.dialog',
fbml: fbmlString,
display: 'dialog',
size: {width:640,height:480}, width:640, height:480
});
$(".FB_UI_Dialog").css('width', $(window).width()*0.8);
}
Run Code Online (Sandbox Code Playgroud)
(注意:我在Facebook论坛上发布了相同的问题而没有回复.我会更新两者,如果有答案的话.)
Javascript代码是从堆栈溢出答案改编而来的.
我在安全的Facebook应用程序页面遇到问题,浏览器报告该页面包含不安全的内容.
不安全的内容似乎是一个请求:http: //static.ak.facebook.com/connect/xd_arbiter.php
但是,来自FB API的所有后续调用都将通过https进行.
我无法弄清楚问题是什么,因为我正在安全地加载我的所有内容,包括FB脚本:https: //connect.facebook.net/en_US/all.js
有任何想法吗?
更新: 似乎这是Facebook自己的错误,修复工作正在进行中:http: //developers.facebook.com/bugs/303558613049120?浏览器= search_4f874a5f45e924383360019
任何人都可以告诉我FB API的工作原理.它看起来是一个基本问题,但我真的很困惑.
问题:我有onlogin().当我单击登录按钮时,我希望它能够调用此功能.但是在我粘贴的代码中:我看到首先打印警报测试,然后调用FB.api.
因此,看起来首先调用onlogin,然后调用FB API ...有一种方法我只能调用此函数一次.
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'XXX', status: true, cookie: true, xfbml: true});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
function checkFacebookLogin() {
FB.api('/me', function(response) {
alert("Name: "+ response.name + "\nFirst name: "+ response.first_name + "ID: "+response.id);
});
alert('test');
}
</script>
<p id="fb_login_button_1"><fb:login-button onlogin="checkFacebookLogin();" size="medium" scope="user_about_me">Sign in using Facebook</fb:login-button></p>
</body>v
Run Code Online (Sandbox Code Playgroud)
我的主要问题是该函数应该只调用一次....但它被调用两次.
html javascript facebook facebook-graph-api 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
我有一个简单的活动创建一个WebView加载Facebook评论,例如
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// myWebView.loadUrl("http://192.168.0.2/facebook.html"); // See 1st image
myWebView.loadUrl("file:///android_asset/facebook.html"); // See 2nd image
}
Run Code Online (Sandbox Code Playgroud)
只有远程html文件的调用才能正常工作,但本地调用不起作用.请参阅以下图像:
通过远程文件

通过本地文件

和内容 facebook.html
![<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</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 = "http://connect.facebook.net/en_US/all.js#xfbml=1&appId=xxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="http://example.com" data-width="470" data-num-posts="10"></div> …Run Code Online (Sandbox Code Playgroud) android android-webview facebook-javascript-sdk facebook-comments android-activity
我开始使用facebook javscript SDK,当我阅读源代码时,我发现了一件有趣的事情.
代码示例如下:
/**
* Annotates a function with a meta object
*/
function annotate(fn, meta) {
meta.superClass = fn.__superConstructor__;
fn.__TCmeta = meta;
return fn;
}
// export to global
__w = annotate;
/**
* when using the annotate function
*/
function sprintf(format) {
// function body
}
__w(sprintf, {"signature":"function(string)"}); // <-- what is the purpose of doing this?
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是用于什么?这样做有什么好处?
仅供参考,整个源代码在这里,你可以看到很多annotate()被使用
我可以在Facebook Graph API的帮助下管理页面对话(读取,写入).但似乎无法在我的直接消息中添加任何附件.
https://developers.facebook.com/docs/graph-api/reference/conversation/messages
我在文档中只看到"message"参数.那么,有什么方法可以做到吗?
facebook facebook-graph-api facebook-javascript-sdk facebook-php-sdk
我javascript在使用Facebook登录Api时在控制台中收到此错误.
The resource at "http://connect.facebook.net/en_US/sdk.js" was blocked because tracking protection is enabled.
// Load the SDK asynchronously
(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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Run Code Online (Sandbox Code Playgroud)
谷歌+插件也被阻止,现在我的Facebook和其他社交网络插件不适用于Firefox 42.0
我使用的是Firefox 42.0
我希望我的网站登录Facebook,但我看到这个错误.
给定的URL未在客户端OAuth设置中列入白名单:此重定向失败,因为重定向URI未在应用的客户端OAuth设置中列入白名单.确保启用了客户端和Web OAuth登录,并将所有应用程序域添加为有效的OAuth重定向URI.
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app …Run Code Online (Sandbox Code Playgroud) facebook facebook-graph-api facebook-javascript-sdk facebook-login
我在这里有一个Facebook JS SDK登录流程:https://web.triller.co/#/user/login
当用户点击Facebook按钮时,执行以下功能:
loginFacebook()
{
const fbPromise = new Promise((resolve, reject) => {
FB.login(resp => {
if (resp.authResponse)
{
resolve(resp.authResponse.accessToken);
}
else
{
console.log(resp);
reject(new Error('Facebook login canceled or failed.'));
}
});
});
return fbPromise
.then(accessToken => api.postJson('user/login_facebook', { accessToken }))
.then(this._handleLogin.bind(this));
}
Run Code Online (Sandbox Code Playgroud)
基本上,它调用FB.login(),并期望收到有效的resp.authResponse.不幸的是,即使在Facebook弹出/标签上成功进行身份验证之后,它也没有.相反,我们{ authResponse: undefined, status: undefined }从浏览器收到以下错误:
不安全的JavaScript尝试启动与URL"框架导航https://m.facebook.com/v2.8/dialog/oauth?foo=bar从URL框架' https://web.triller.co/#/ user/login?_k = cmzdb6 '.尝试导航的帧既不是与目标相同的原点,也不是目标的父或开启者.
在Facebook弹出/选项卡中进行身份验证后会立即发生错误,并且只会在Android Chrome上发生.桌面Chrome(在Mac上)不会显示相同的错误.iOS上的Safari也不会显示错误.
对于发生了什么的任何想法?为什么Android Chrome和桌面Chrome之间存在差异?它可能与URL中的哈希有关吗?
javascript facebook google-chrome cross-domain facebook-javascript-sdk
facebook ×6
javascript ×5
android ×1
annotations ×1
cross-domain ×1
firefox ×1
html ×1
https ×1
php ×1