我已经在Xcode 6中集成了Facebook sdk(使用swift).在登录期间,我请求public_profile权限:
FBSession.openActiveSessionWithReadPermissions(["public_profile"], allowLoginUI: true, completionHandler: {
...
...
Run Code Online (Sandbox Code Playgroud)
所以我请求用户的信息:
FBRequestConnection.startForMeWithCompletionHandler { (connection, user, error) -> Void in
...
...
Run Code Online (Sandbox Code Playgroud)
为什么用户对象不包含个人资料图片?如何获取用户个人资料图片?它不是public_profile的一部分?
我得到以下信息:
2015-01-25 01:25:18.858 Test[767:23804] {
"first_name" = xxx;
gender = xxx;
id = xxxxxxxxx;
"last_name" = xxxxxx;
link = "https://www.facebook.com/app_scoped_user_id/xxxxxxxxx/";
locale = "xxxxx";
name = "xxxxxxx xxxxxxx";
timezone = 1;
"updated_time" = "2013-12-21T18:45:29+0000";
verified = 1;
}
Run Code Online (Sandbox Code Playgroud)
PS:隐私的xxx
我使用最后一个FBSDK(使用swift)
// MARK: sign in with facebook
func signInWithFacebook()
{
if (FBSDKAccessToken.currentAccessToken() != nil)
{
// User is already logged in, do work such as go to next view controller.
println("already logged in ")
self.returnUserData()
return
}
var faceBookLoginManger = FBSDKLoginManager()
faceBookLoginManger.logInWithReadPermissions(["public_profile", "email", "user_friends"], handler: { (result, error)-> Void in
//result is FBSDKLoginManagerLoginResult
if (error != nil)
{
println("error is \(error)")
}
if (result.isCancelled)
{
//handle cancelations
}
if result.grantedPermissions.contains("email")
{
self.returnUserData()
}
})
}
func returnUserData()
{
let graphRequest …Run Code Online (Sandbox Code Playgroud) 我不明白为什么他们不是一个明确的教程或指南,所以我希望我的问题可以在这里得到解答.
因此,尝试通过Web Api注册来自Facebook或谷歌的用户.
问题是,在这个RegisterExternal方法上,这一行:
var info = await Authentication.GetExternalLoginInfoAsync();
Run Code Online (Sandbox Code Playgroud)
它返回null,因此返回a BadRequest()
到目前为止我得到了什么:
在Startup.Auth.cs我已经知道了id和秘密,请注意我也尝试过使用Microsoft.Owin.Security.Facebook
var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions
{
AppId = "103596246642104",
AppSecret = "1c9c8f696e47bbc661702821c5a8ae75",
Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, ClaimValueTypes.String, "Facebook"));
return Task.FromResult(0);
}
},
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "328779658984-t9d67rh2nr681bahfusan0m5vuqeck13.apps.googleusercontent.com",
ClientSecret = "ZYcNHxBqH56Y0J2-tYowp9q0",
CallbackPath = new PathString("/api/Account/ManageInfo")
});
Run Code Online (Sandbox Code Playgroud)
facebookOptions来源:这篇文章
额外的facebookOptions没有解决问题.
我能够从谷歌和Facebook检索access_token.我也可以使用此access_token进行身份验证api/Account/UserInfo
GET http://localhost:4856/api/Account/UserInfo
in the header:
Authorization: Bearer R9BTVhI0...
Run Code Online (Sandbox Code Playgroud)
哪个回报: …