我已经在一个网站上实现了邀请你的朋友功能。
最近它停止了工作(由于“稳定”的 Facebook 图形 API 的持续乐趣......)
我试图绕过这个但没有运气。
每当我与朋友选择器框架交互时,我都会收到以下错误:
阻止来源为“ https://www.facebook.com ”的框架访问来源为“ http://myDomain.com ”的框架。请求访问的帧具有“https”协议,被访问的帧具有“http”协议。协议必须匹配。
我的网络应用程序确实是在 http 而不是 https,但是这个错误是新的,因为这个功能在过去有效。
这是我用来打开朋友选择器框架的代码:
function sendRequestViaMultiFriendSelector() {
window.fbAsyncInit();
FB._inCanvas = true;
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
FB.ui({method: 'apprequests',
message: 'my message to my friends goes here'
}, function(response) {
console.log('requestCallback');
console.log('request: '+response.request);
console.log('to: '+response.to);
//write response values to DB goes here...
});
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else {
console.log('sendRequestViaMultiFriendSelector, not connected');
FB.login(function(response) {
if (response.authResponse) {
console.log('starting again');
sendRequestViaMultiFriendSelector();
} else {
console.log('User cancelled login or did not fully authorize.');
on_fb_fail();//...
}
}, {scope: "email,"+
"user_about_me,"+
"publish_stream"});
}
});
}
这是我用来初始化 FB api 的代码
console.log('>> window.environment: '+window.environment);
window.fbAsyncInit = function() {
console.log('window.fbAsyncInit, window.fb_inited: '+window.fb_inited);
if(window.fb_inited === false){
console.log('executing window.fbAsyncInit...');
//if (navigator.appName.indexOf("Microsoft") != -1) {
//if(/msie/gi.test(navigator.userAgent) ){
if(navigator.appName === 'Microsoft Internet Explorer'){
window.fb_inited = true;
FB.init({
appId : 'MY_APP_ID', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true,
frictionlessRequests : true
});
} else {
window.fb_inited = true;
FB.init({
appId : 'MY_APP_ID', // App ID
channelUrl : 'http://www.myDomain.com/channel.cfm', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true,
frictionlessRequests : true
});
}
console.log('window.fb_inited: '+window.fb_inited);
}
// Additional initialization code here
};
(function(d, s, id){
window.fb_inited = false;
console.log('Loading FB JS-SDK asynchronously...');
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";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
这是我的频道.cfm
<cfsilent>
<cfparam name="url.localeCode" default="en_US" />
<cfset cacheExpire = 60 * 60 * 24 * 365 />
<cfheader name="Pragma" value="public" />
<cfheader name="Cache-Control" value="maxage=#cacheExpire#" />
<cfheader name="Expires" value="#getHttpTimeString(dateAdd('d', now(), 365))#">
</cfsilent>
<cfoutput>
<script src="//connect.facebook.net/#url.localeCode#/all.js"></script>
</cfoutput>
这是来自 channel.php 的快速 cf 端口,我也尝试过...
<?php
$cache_expire = 60*60*24*365;
header("Pragma: public");
header("Cache-Control: max-age=".$cache_expire);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');
?>
<script src="//connect.facebook.net/en_US/all.js"></script>
真的很感激我听到 Facebook 没有更新他们的参考与他们的变化同步的任何想法,因此使用他们的 API 的“乐趣”......我的脚本基于这些链接:FB.init - https://developers。 facebook.com/docs/reference/javascript/ FB 好友请求 - https://developers.facebook.com/docs/reference/dialogs/requests/