この API はまったく新しいので、Facebook API を使用してログインを許可する Web サイトに取り組んでいます。コードが古くて機能しないため、新しい 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) 認証コードがありません
データベースに ID が既にあるため、C# でプロファイル情報を取得する方法を誰かが教えてくれる場合は、ユーザーの 1 人としてログインするだけです。