Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.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
Iphone 如何在ios 6中获取Facebook好友?_Iphone_Ios_Objective C_Xcode_Facebook - Fatal编程技术网

Iphone 如何在ios 6中获取Facebook好友?

Iphone 如何在ios 6中获取Facebook好友?,iphone,ios,objective-c,xcode,facebook,Iphone,Ios,Objective C,Xcode,Facebook,我想从我的应用程序发送邀请facebook好友,就像在Instagram应用程序中一样 但是我找不到任何好的教程 我可以获取朋友的姓名和id,但无法获取朋友的个人资料图像、姓名等的url。 我的代码如下: NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"]; SLRequest *request = [SLRequest requestForServiceType:SLSe

我想从我的应用程序发送邀请facebook好友,就像在Instagram应用程序中一样

但是我找不到任何好的教程

我可以获取朋友的姓名和id,但无法获取朋友的个人资料图像、姓名等的url。

我的代码如下:

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)
        {
            list =[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];

            NSLog(@"Dictionary contains data: %@", list );
            if([list objectForKey:@"error"]!=nil)
            {
                [self attemptRenewCredentials];
            }
            dispatch_async(dispatch_get_main_queue(),^{
                nameLabel.text = [list objectForKey:@"username"];
            });
        }
        else{
            //handle error gracefully
            NSLog(@"error from get%@",error);
            //attempt to revalidate credentials
        }

    }];

那么,我如何才能做到这一点呢?

您应该将其包含在参数中

[ NSMutableDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,link,gender,last_name,first_name",@"fields",nil]

这是获取好友列表的代码

  ACAccountStore *accountStore = [[ACAccountStore alloc] init];
__block ACAccount *facebookAccount = nil;

ACAccountType *facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

// Specify App ID and permissions
NSDictionary *options = @{
 ACFacebookAppIdKey: @"add_here_your_project_FB_ID",
 ACFacebookPermissionsKey: @[@"publish_stream", @"publish_actions",@"read_friendlists"],
 ACFacebookAudienceKey: ACFacebookAudienceFriends
};

[accountStore requestAccessToAccountsWithType:facebookAccountType
                                      options:options completion:^(BOOL granted, NSError *error)
 {
     if (granted)
     {
         NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];

         facebookAccount = [accounts lastObject];
     }
     else {

         NSLog(@"error.localizedDescription======= %@", error.localizedDescription);
     }

 }];

NSArray *accounts = [accountStore accountsWithAccountType:facebookAccountType];
facebookAccount = [accounts lastObject];

//NSString *acessToken = [NSString stringWithFormat:@"%@",facebookAccount.credential.oauthToken];
//NSDictionary *parameters = @{@"access_token": acessToken};

NSDictionary *param=[NSDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,link,gender,last_name,first_name,username",@"fields", nil];

NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];
SLRequest *feedRequest = [SLRequest
                          requestForServiceType:SLServiceTypeFacebook
                          requestMethod:SLRequestMethodGET
                          URL:feedURL
                          parameters:param];
feedRequest.account = facebookAccount;
[feedRequest performRequestWithHandler:^(NSData *responseData,
                                         NSHTTPURLResponse *urlResponse, NSError *error)
 {
     if(!error)
     {
         id json =[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

         NSLog(@"Dictionary contains data: %@", json );
         if([json objectForKey:@"error"]!=nil)
         {
             //[self attemptRenewCredentials];
         }
         dispatch_async(dispatch_get_main_queue(),^{
             //nameLabel.text = [json objectForKey:@"username"];
         });
     }
     else{
         //handle error gracefully
         NSLog(@"error from get%@",error);
         //attempt to revalidate credentials
     }
 }];

我希望它能帮助你。谢谢

你试过什么?但是我应该在哪里写这行??“图片,身份证,姓名,链接,性别,姓,名”在参数中,我一直在获取朋友列表,但我无法获取他们的姓名,个人资料图片等。请尝试我编辑的代码,让我知道它是否工作。谢谢你的回复!但是我没法拿到pic_square。你能拿到朋友的其他详细信息吗?我只能拿到id和姓名。我认为这个查询不起作用,因为当我尝试只使用url时,我得到了相同的结果。