ios - 使用我自己的 UIButton 获取用户 Facebook 信息
<p><p>我正在尝试创建一个 Facebook 连接按钮,我需要在连接时为此获取 FBGraphUser。我的 Button 上有以下代码:</p>
<pre><code>-(IBAction)fbButtonClickHandler:(id)sender {
mainDelegate = (AppDelegate*)[delegate];
if (mainDelegate.fbSession.isOpen) {
; // FB delog
}
else {
if (mainDelegate.fbSession.state != FBSessionStateCreated) {
mainDelegate.fbSession = [ initWithPermissions:];
}
// loggin on facebook
[mainDelegate.fbSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
forState:UIControlStateNormal];
// reading the documentation i'm trying this to get the FBGraphUser
if(session.isOpen) {
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id<FBGraphUser> user, NSError *error) {
if (!error) {
NSString *userInfo = @"";
// Example: typed access (name)
// - no special permissions required
userInfo = [userInfo
stringByAppendingString:
[NSString stringWithFormat:@"Name: %@\n\n",
user.name]];
// Example: typed access, (birthday)
// - requires user_birthday permission
userInfo = [userInfo
stringByAppendingString:
[NSString stringWithFormat:@"Birthday: %@\n\n",
user.birthday]];
// Display the user info
NSLog(@"%@", userInfo);
}
NSLog(@" error: %@" , error);
}];
}
}
}];
}
}
</code></pre>
<p>问题是当我调用 <code>startForMeWithCompletionHandler</code> 时它失败了:</p>
<pre> 错误:HTTP 状态码:400
FBSDKLog:响应:
操作无法完成。 (com.facebook.sdk 错误 5。)
(无效的)
错误:错误域=com.facebook.sdk 代码=5“操作无法完成。
(com.facebook.sdk 错误 5。)“UserInfo=0x925f760 {com.facebook.sdk:ParsedJSONResponseKey=
{type = 可变字典,count = 2,
条目 =>
1:{内容=“代码”}=
{值 = +400,类型 = kCFNumberSInt32Type}
2 : {contents = "body"} = {type = mutable dict, count = 1,
条目 =>
11 : {contents = "error"} = {type = mutable dict, count = 3,
条目 =>
2 : {contents = "type"} = {contents = "OAuthException"}
3 : {contents = "message"} = {contents = "必须使用事件访问 token 来查询有关信息
当前用户。"}
6 : {内容 = "代码"} = 2500
</pre>
<p>我错过了什么吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>显然,FBRequestConnection 在 FBSession 中使用了一个名为 active session 的变量来使其在之后工作</p>
<pre><code> [mainDelegate.fbSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
</code></pre>
<p>放:</p>
<pre><code>FBSession.activeSession = session;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 使用我自己的 UIButton 获取用户 Facebook 信息,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/12951135/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/12951135/
</a>
</p>
页:
[1]