繁体   English   中英

从Social.framework获取Facebook访问令牌(iOS6)

[英]Get Facebook access token from Social.framework(iOS6)

我需要检索我的系统帐户的Facebook访问令牌,我在设置应用程序中设置。

我知道Social.framework(iOS6)知道我所有的FB帐户信息,我可以使用SLRequest类对Graph API执行API调用,就像这篇文章http://blogs.captechconsulting.com/blog/eric-stroh/ios- 6教程整合Facebook的-你的应用程序

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

我找到了Twitter的解决方案https://dev.twitter.com/docs/ios/using-reverse-auth ,但是你可以帮我解决Facebook问题吗?

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

@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");
    }
}];

暂无
暂无

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

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