这是一个全新的API,我在一个网站上工作,它使用Facebook API来允许他们登录。代码是旧的,现在不能工作,所以我试图升级到使用新的SDK。我正确地让他们使用以下命令登录:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: '<%= System.Configuration.ConfigurationManager.AppSettings["ApiID"] %>', // App ID
channelUrl: 'http://<%= Request.ServerVariables["SERVER_NAME"] %>/channel.html', // Channel File
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
};
// 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));
</script>和这个链接:
<strong><a href="#" class="sIcoFB" onclick="FB.login(function(response) { if (response.authResponse) { scope: 'publish_stream,email'; parent.location = '<%=Server.UrlDecode(redirectPath)%>'; } else { alert('Please sign in to access the site'); } });">Login using Facebook</a></strong> 这似乎是工作,因为然后您可以打开facebook.com,您可以正确登录。然而,我似乎找不到如何在C#中检查这一点。到目前为止,我有这样的想法:
//Facebook Authenticated, created session and API object
_connectSession = new FacebookClient();
//example of getting access code
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("client_id", System.Configuration.ConfigurationManager.AppSettings["ApiID"]);
parameters.Add("redirect_uri", Request.Url.AbsoluteUri);
parameters.Add("client_secret", System.Configuration.ConfigurationManager.AppSettings["Secret"]);
parameters.Add("scope", "publish_stream,email");
IDictionary<string, object> result = (IDictionary<string, object>)_connectSession.Get("/oauth/access_token", parameters);
string accessToken = (string)result["access_token"];然而,我得到了这个错误:
(OAuthException - #1)缺少授权码
如果有人可以告诉我如何在C#中获取配置文件信息,因为我们的数据库中已经有ID,我只需要将他们作为我们的用户之一登录即可。
发布于 2012-10-04 02:29:51
您缺少获取access_token所需的code参数-异常似乎是正确的。检查Authentication文档中的服务器端流程
您可能只需要包括用户从身份验证对话框重定向回您的应用程序时收到的code参数-用于获取访问令牌的调用中的其他参数看起来是正确的
发布于 2012-10-05 03:00:45
我有下面的测试页面,这是直接从Facebook开发人员的代码。它会提示您登录,然后将您的图片和姓名放入元素中。虽然它可以让您正确登录,但它不会更新。
**更新了代码,现在可以工作了*
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testfb.aspx.cs" Inherits="testfb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="/js/jquery-1.6.1.min.js" charset="utf-8"> </script>
<script src="/js/jquery-ui-1.8.custom.min.js" type="text/javascript"></script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: '111081862265698', // App ID
channelUrl: '//<%= Request.ServerVariables["SERVER_NAME"] %>/channel.html', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.login(function (response) {
if (response.authResponse) {
alert('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
alert('Good to see you, ' + response.name + '.');
var image = document.getElementById('image');
image.src = 'http://graph.facebook.com/' + response.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = response.name
});
} else {
alert('User cancelled login or did not fully authorize.');
}
});
};
// 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));
</script>
<div align="center">
<img id="image"/>
<div id="name"></div>
</div>
<div class="fb-login-button" scope="email">
Login with Facebook
</div>
</body>
</html>https://stackoverflow.com/questions/12714225
复制相似问题