在IOS6中邀请Facebook好友

时间:2013-05-07 09:37:57

标签: iphone ios objective-c xcode facebook

我想要获取facebook好友列表&发送我的应用邀请。

我尝试了以下代码:

 ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];


    NSLog(@"%@",accounts); `******//I got the null array ***********`
    ACAccount *facebookAccount = [accounts lastObject];
    NSString *acessToken = [NSString stringWithFormat:@"%@",facebookAccount.credential.oauthToken];

    NSDictionary *parameters = @{@"access_token": acessToken};
    NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];
    SLRequest *feedRequest = [SLRequest
                              requestForServiceType:SLServiceTypeFacebook
                              requestMethod:SLRequestMethodGET
                              URL:feedURL
                              parameters:parameters];
    feedRequest.account = facebookAccount;
    [feedRequest performRequestWithHandler:^(NSData *responseData,
                                             NSHTTPURLResponse *urlResponse, NSError *error)
     {
         NSLog(@"%@",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
     }];

1 个答案:

答案 0 :(得分:0)

在iOS 6中使用facebook SDK:

#import <FacebookSDK/FacebookSDK.h>

并致电:

[FBRequestConnection startForMyFriendsWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];

结果应该是您正在寻找的数据。