gpt4 book ai didi

ios - 从 Social.framework(iOS6) 获取 Facebook 访问 token

转载 作者:IT王子 更新时间:2023-10-29 07:59:26 24 4
gpt4 key购买 nike

我需要检索我在“设置”应用程序中设置的系统帐户的 Facebook 访问 token 。

我知道 Social.framework(iOS6) 知道我所有的 FB 帐户信息,我可以使用 SLRequest 类对 Graph API 执行 API 调用,就像在这篇文章中一样 http://blogs.captechconsulting.com/blog/eric-stroh/ios-6-tutorial-integrating-facebook-your-applications

但是,我的问题是 - 如何检索我的 Facebook 系统帐户的访问 token ?

我找到了 Twitter 的解决方案 https://dev.twitter.com/docs/ios/using-reverse-auth , 但你能帮我用 Facebook 吗

最佳答案

如果您已经知道如何设置帐户存储,这里的代码显示了如何获取访问 token :

@property (strong, nonatomic) ACAccountStore *accountStore;
@property (strong, nonatomic) ACAccount *fbAccount;

...

@synthesize accountStore = _accountStore;
@synthesize fbAccount = _fbAccount;

...

// Initialize the account store
self.accountStore = [[ACAccountStore alloc] init];

// Get the Facebook account type for the access request
ACAccountType *fbAccountType = [self.accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// Request access to the Facebook account with the access info
[self.accountStore requestAccessToAccountsWithType:fbAccountType
options:fbInfo
completion:^(BOOL granted, NSError *error) {
if (granted) {
// If access granted, then get the Facebook account info
NSArray *accounts = [self.accountStore
accountsWithAccountType:fbAccountType];
self.fbAccount = [accounts lastObject];

// Get the access token, could be used in other scenarios
ACAccountCredential *fbCredential = [self.fbAccount credential];
NSString *accessToken = [fbCredential oauthToken];
NSLog(@"Facebook Access Token: %@", accessToken);


// Add code here to make an API request using the SLRequest class

} else {
NSLog(@"Access not granted");
}
}];

关于ios - 从 Social.framework(iOS6) 获取 Facebook 访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13930371/

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