简体   繁体   English

如何从iOS SDK中的Facebook对象获取Facebook用户ID?

[英]How do I get the Facebook user Id from the Facebook object in the iOS SDK?

I see that the access token is available in the Facebook object, but I don't see a Facebook user Id. 我看到访问令牌在Facebook对象中可用,但我没有看到Facebook用户ID。

I could make a graph request to "me" to get the Facebook Id, but I'd prefer not to make the extra api call. 我可以向“我”发出图形请求以获取Facebook ID,但我不想进行额外的api调用。

There is an easy way to get this these days; 这些天有一个简单的方法来获得这个; assuming you already have a FBSession open, you could just do this: 假设您已经打开了FBSession ,您可以这样做:

[FBRequestConnection startForMeWithCompletionHandler:
  ^(FBRequestConnection *connection, id result, NSError *error)
  {
      NSLog(@"facebook result: %@", result);
  }];

You will have to call /me to get the id. 你将不得不打电话/我来获取身份证。 iOS access tokens are now encrypted and thus you won't be able to parse the user id from it. iOS访问令牌现在已加密,因此您无法从中解析用户ID。 Also, server side tokens will all be encrypted with oauth 2.0 soon too. 此外,服务器端令牌也将很快用oauth 2.0加密。

You can just use this: 你可以使用这个:

[[account valueForKey:@"properties"] valueForKey:@"uid"]

E-mail can be found with this: 电子邮件可以找到:

[[account valueForKey:@"properties"] valueForKey:@"ACUIDisplayUsername"]

where account is ACAccount type of course 其中帐户是ACAccount类型的课程

可以使用[FBSession activeSession] .accessTokenData.userID获取它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM