2014-10-29 64 views
0

我已經更新了圖Api的版本到v2。現在我面臨的問題是,當我執行以下代碼它顯示我空數組:用戶好友在Facebook上顯示空列表Sdk Graph Api v2

FBRequest *friendsRequest = [FBRequest requestForMyFriends]; 
     [friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *result, NSError *error) { 
      NSArray *friendshipid; 
      NSString *username; 
      if (!error) { 
       NSLog(@"friends = %@", [result description]); 

      } 
      if (completion) { 
       completion(friendshipid, username, error); 
      } 
     }]; 
    } 
} 

我才知道,Facebook的SDK已經爲用戶朋友們的一些變化,現在它已採取許可對於user_friends,但我不知道在哪裏進行更改,要求許可user_friends

+0

不贊成這種方式在V2.1中,如果u [R從Facebook下載示例項目,嘗試friendpickersample或scrumptos – 2014-10-29 06:34:42

+0

非常感謝,我只是JAVE看看的樣本項目。 – Purva 2014-10-29 06:41:09

回答

1

您可以使用給定的代碼段。在這裏,我使用了Social Framework的類來獲得Facebook friends。希望它能爲你工作。

- (void) connectWithFacebookFriends 
{ 
    ACAccountStore *accountStore = [[ACAccountStore alloc] init]; 

    ACAccountType *accountTypeFacebook = [accountStore accountTypeWithAccountTypeIdentifier: 
    ACAccountTypeIdentifierFacebook]; 

    NSDictionary *options = @{ACFacebookAppIdKey: kFaceBookId, 
           ACFacebookPermissionsKey: @[@"user_friends"], 
           ACFacebookAudienceKey: ACFacebookAudienceFriends 
           }; 

    [accountStore requestAccessToAccountsWithType:accountTypeFacebook 
              options:options 
             completion:^(BOOL granted, NSError *error) 
    { 
     if(granted) { 

      NSArray *accounts = [accountStore 
           accountsWithAccountType:accountTypeFacebook]; 
      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 performRequestWithHandler:^(NSData *responseData, 
             NSHTTPURLResponse *urlResponse, NSError *error) 
      { 

       NSString * str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
       DLog(@"%@",str); 


       NSLog(@"Request failed, %@", [urlResponse description]); 
      }]; 
     } else { 
      NSLog(@"Access Denied"); 
      NSLog(@"[%@]",[error localizedDescription]); 

     } 
    }]; 

} 
相關問題