我使用facebook和twiiter验证我的asp.net网站。 我的应用程序是一个产品,因此不同的用户具有不同的App_Id进行身份验证。 所以我想动态传递它,我从数据库中获取了App_Id。 我使用“aspsnippets.facebookapi.dll”,使用它可以动态分配App_Id 如下
List<SocialLoginModal> listLoginSocial = new List<SocialLoginModal>();
listLoginSocial = dalLoginSocial.getBind();
if (listLoginSocial.Count > 0)
{
//FACEBOOK Keys
List<SocialLoginModal> listFBLogin = new List<SocialLoginModal>();
listFBLogin = listLoginSocial.Where(x => x.AuthenticationName == "Facebook").ToList();
if (listFBLogin.Count > 0)
{
FaceBookConnect.API_Key = Convert.ToString(listFBLogin[0].Api_Key);
FaceBookConnect.API_Secret = Convert.ToString(listFBLogin[0].Api_Secret);
fbId.Value = Convert.ToString(listFBLogin[0].Api_Key);
}
//TWITTER Keys
List<SocialLoginModal> listTwitterLogin = new List<SocialLoginModal>();
listTwitterLogin = listLoginSocial.Where(x => x.AuthenticationName == "Twiiter").ToList();
if (listTwitterLogin.Count > 0)
{
TwitterConnect.API_Key = Convert.ToString(listTwitterLogin[0].Api_Key);
TwitterConnect.API_Secret = Convert.ToString(listTwitterLogin[0].Api_Secret);
}
}
它工作正常, 但问题是我不会与godaddy服务器一起工作。 所以我转到sdk,如下所示
<script type="text/javascript">
var fbId = document.getElementById('<%=fbId.ClientID%>').value;
// Load the SDK Asynchronously
(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));
// Init the SDK upon load
window.fbAsyncInit = function() {
FB.init({
appId : '273672922689018', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
FB.api('/me', function(me) {
if (me.name) {
document.getElementById('auth-displayname').innerHTML = me.name;
}
})
document.getElementById('auth-loggedout').style.display = 'none';
document.getElementById('auth-loggedin').style.display = 'block';
} else {
// user has not auth'd your app, or is not logged into Facebook
document.getElementById('auth-loggedout').style.display = 'block';
document.getElementById('auth-loggedin').style.display = 'none';
}
});
$("#auth-logoutlink").click(function() {
FB.logout(function() {
window.location.reload();
});
});
}
</script>
我试图将值动态传递给appid,如下所示
var fbId = document.getElementById('&lt;%= fbId.ClientID%&gt;')。value;
并将其指定为应用ID为
FB.init({
appId : fbId , // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
它不起作用.. 如何在该地方动态传递app id
答案 0 :(得分:1)
window.fbAsyncInit = function () {
FB.init({
appId: '<%= ConfigurationManager.AppSettings["FBsubAppId"] %>', // App ID
oauth: true,
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
version: 'v2.0' // New
});
};