gpt4 book ai didi

iphone - Facebook SSO 并请求 iOS SDK

转载 作者:行者123 更新时间:2023-11-29 13:46:33 25 4
gpt4 key购买 nike

我正在尝试向当前用户发布留言墙。在执行请求之前,我正在验证 session 并在未验证时进行授权。为了澄清,我省略了一些声明和变量的初始化。问题在于此处显示的代码是在执行 fbDidLogin-delegate 方法之前执行的。所以看起来 Facebook 对象在请求之前没有有效的访问 token 。我做了一个单例。下次我运行该程序时它会起作用。

代表

- (void)fbDidLogin 
{
NSLog(@"DEBUG: DID LOG IN");

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}

View Controller

Facebook *facebook = [SocialMedia sharedFacebookAuthorized];

NSString *name = nil;
NSString *message = nil;
NSString *picture = nil;

if (self.didPassTest) {
// Code
} else {
// Code
}

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
name, @"name",
message, @"message",
picture, @"picture",
description, @"description",
link, @"link",
caption, @"caption", nil];

[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

SharedFacebook..功能

+ (Facebook *)sharedFacebookAuthorized 
{
[self sharedFacebook];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}

NSArray *permissions = [[NSArray arrayWithObjects:@"email", @"read_stream", @"publish_stream", nil] retain];

NSLog(@"START?");

if (![facebook isSessionValid]) {
[facebook authorize:permissions];
NSLog(@"INSIDE?");
}

NSLog(@"CONTINUE?");
return facebook;
}

最佳答案

这是一个异步任务。在从图形 API 请求任何内容之前,您必须等待授权异步调用完成。在这里查看我对类似问题的回答:How to react to asynchronous events (login)?

关于iphone - Facebook SSO 并请求 iOS SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7151737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com