Подтвердить что ты не робот

Получить токен доступа Facebook из Social.framework(iOS6)

Мне нужно получить токен доступа к Facebook моей системной учетной записи, который я установил в приложении "Настройки".

Я знаю, что Social.framework(iOS6) знает всю информацию о моей учетной записи FB, и я могу выполнять вызовы API для Graph API с использованием класса SLRequest, например, в этом сообщении http://blogs.captechconsulting.com/blog/eric-stroh/ios-6-tutorial-integrating-facebook-your-applications

Но, мой вопрос: как я могу получить токен доступа к учетной записи системы Facebook?

Я нашел решение для Twitter https://dev.twitter.com/docs/ios/using-reverse-auth, но вы могли бы помочь мне с Facebook

4b9b3361

Ответ 1

Если вы уже знаете, как настроить хранилище учетных записей, здесь код вокруг него показывает, как получить токен доступа:

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