サイトに友達招待機能を実装しました。
最近、それは機能しなくなりました (「安定した」Facebook グラフ API の継続的な喜びのため...)
運が悪いので、これに頭を悩ませようとしています。
フレンド セレクター フレームを操作するたびに、次のエラーが表示されます。
オリジンが「 https://www.facebook.com 」のフレームが、オリジンが「 http://myDomain.com 」のフレームにアクセスするのをブロックしました。アクセスを要求するフレームのプロトコルは「https」、アクセスされるフレームのプロトコルは「http」です。プロトコルが一致する必要があります。
私のWebアプリは確かにhttpsではなくhttpにありますが、この機能は過去に機能していたため、このエラーは新しいものです。
これは、フレンド セレクター フレームを開くために使用するコードです。
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/