Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用社交框架登录并列出Facebook好友_Ios_Objective C_Facebook_Social Framework - Fatal编程技术网

Ios 使用社交框架登录并列出Facebook好友

Ios 使用社交框架登录并列出Facebook好友,ios,objective-c,facebook,social-framework,Ios,Objective C,Facebook,Social Framework,有人能给我一些关于如何整合的建议吗?我的目标是获得安装我的应用程序(fb应用程序)的朋友列表。最初,我需要先将用户登录到我的应用程序,并列出已安装/未安装该应用程序的朋友 PS:我不想使用Facebook SDK。我曾经做过噩梦,因为facebook曾无数次更改sdk =========== 更新 我已成功登录并列出我的facebook好友。但现在我的问题是列出我的朋友谁有应用程序和列表图片以及。我试过这个: 网址: 这给我带来了异常:必须使用活动访问令牌来查询有关当前用户的信息。问题 我也试过

有人能给我一些关于如何整合的建议吗?我的目标是获得安装我的应用程序(fb应用程序)的朋友列表。最初,我需要先将用户登录到我的应用程序,并列出已安装/未安装该应用程序的朋友

PS:我不想使用Facebook SDK。我曾经做过噩梦,因为facebook曾无数次更改sdk

=========== 更新

我已成功登录并列出我的facebook好友。但现在我的问题是列出我的朋友谁有应用程序和列表图片以及。我试过这个:

网址:


这给我带来了异常:必须使用活动访问令牌来查询有关当前用户的信息。问题

我也试过了,没有提到错误


如果我只尝试
me/friends
,它会列出我所有的朋友

首先在项目中导入社交、帐户、系统配置框架。 然后在.m文件中使用此代码

-(void)facebook
{
    self.accountStore = [[ACAccountStore alloc]init];
    ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    NSString *key = @"XXXXXXXXXXXXX";//get your key form creating new app in facebook app section
    NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"email"],ACFacebookPermissionsKey, nil];

    [self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
     ^(BOOL granted, NSError *e) {
         if (granted)
         {
             NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
             //it will always be the last object with single sign on
             self.facebookAccount = [accounts lastObject];


             ACAccountCredential *facebookCredential = [self.facebookAccount credential];
             NSString *accessToken = [facebookCredential oauthToken];
             NSLog(@"Facebook Access Token: %@", accessToken);


             NSLog(@"facebook account =%@",self.facebookAccount);

             [self get];

             [self getFBFriends];

             isFacebookAvailable = 1;
         } else
         {
             //Fail gracefully...
             NSLog(@"error getting permission yupeeeeeee %@",e);
             sleep(10);
             NSLog(@"awake from sleep");
             isFacebookAvailable = 0;

         }
     }];
   }

-(void)get
{

    NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me"];

    SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:requestURL parameters:nil];
    request.account = self.facebookAccount;

    [request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {

        if(!error)
        {

            NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

            NSLog(@"Dictionary contains: %@", list );

            fbID = [NSString stringWithFormat:@"%@", [list objectForKey:@"id"]];
            globalFBID = fbID;

            gender = [NSString stringWithFormat:@"%@", [list objectForKey:@"gender"]];
            playerGender = [NSString stringWithFormat:@"%@", gender];
            NSLog(@"Gender : %@", playerGender);


            self.globalmailID   = [NSString stringWithFormat:@"%@",[list objectForKey:@"email"]];
            NSLog(@"global mail ID : %@",globalmailID);

              fbname = [NSString stringWithFormat:@"%@",[list objectForKey:@"name"]];
            NSLog(@"faceboooookkkk name %@",fbname);

            if([list objectForKey:@"error"]!=nil)
            {
                [self attemptRenewCredentials];
            }
            dispatch_async(dispatch_get_main_queue(),^{

            });
        }
        else
        {
            //handle error gracefully
            NSLog(@"error from get%@",error);
            //attempt to revalidate credentials
        }

    }];

    self.accountStore = [[ACAccountStore alloc]init];
    ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    NSString *key = @"451805654875339";
    NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"friends_videos"],ACFacebookPermissionsKey, nil];


    [self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
     ^(BOOL granted, NSError *e) {}];

}



-(void)getFBFriends
{

    NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];

    SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodGET URL:requestURL parameters:nil];
    request.account = self.facebookAccount;

    [request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {

        if(!error)
        {

            NSDictionary *friendslist =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

            for (id facebookFriendList in [friendslist objectForKey:@"data"])
            {
                NSDictionary *friendList = (NSDictionary *)facebookFriendList;
                [facebookFriendIDArray addObject:[friendList objectForKey:@"id"]];
            }


            if([friendslist objectForKey:@"error"]!=nil)
            {
                [self attemptRenewCredentials];
            }
            dispatch_async(dispatch_get_main_queue(),^{

            });
        }
        else
        {
            //handle error gracefully
            NSLog(@"error from get%@",error);
            //attempt to revalidate credentials
        }

    }];

    self.accountStore = [[ACAccountStore alloc]init];
    ACAccountType *FBaccountType= [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

    NSString *key = @"451805654875339";
    NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:key,ACFacebookAppIdKey,@[@"friends_videos"],ACFacebookPermissionsKey, nil];


    [self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
     ^(BOOL granted, NSError *e) {}];

}


-(void)accountChanged:(NSNotification *)notification
{
    [self attemptRenewCredentials];
}

-(void)attemptRenewCredentials
{
    [self.accountStore renewCredentialsForAccount:(ACAccount *)self.facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error){
        if(!error)
        {
            switch (renewResult) {
                case ACAccountCredentialRenewResultRenewed:
                    NSLog(@"Good to go");
                    [self get];
                    break;
                case ACAccountCredentialRenewResultRejected:
                    NSLog(@"User declined permission");
                    break;
                case ACAccountCredentialRenewResultFailed:
                    NSLog(@"non-user-initiated cancel, you may attempt to retry");
                    break;
                default:
                    break;
            }

        }
        else{
            //handle error gracefully
            NSLog(@"error from renew credentials%@",error);
        }
    }];
}

我终于明白了,显然你不能在URL中追加内容。您需要将参数中的字段传递到
SLRequest

NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];

NSDictionary *param=[NSDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,installed",@"fields", nil];

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                        requestMethod:SLRequestMethodGET
                                                  URL:requestURL
                                           parameters:param];

谢谢但获得facebook好友是可行的,但我的问题是获得安装了我的facebook应用程序的好友。您是否在UrlOAutheException中尝试过此操作:必须使用活动访问令牌来查询有关当前用户的信息。问题由于要解决此问题,您必须获取访问令牌检查我自己的答案,因此出现此错误。无法在图形url内追加字段。希望有人觉得这有帮助。怎么可能呢?我只得到了朋友的总数。