2014-01-31 4 views
0

누군가가 저에게 이것을 통합하는 방법에 대한 조언을 해줄 수 있습니까? 내 목표는 내 앱 (fb 앱)을 설치 한 친구 목록을 얻는 것입니다. 처음에는 내 앱에 사용자를 로그인하고 앱을 설치하지 않은 친구를 나열해야합니다.Social Framework를 사용하여 로그인하고 페이스 북의 친구를 나열하십시오

추신 : 나는 Facebook SDK를 사용하고 싶지 않습니다. 나는 페이스 북으로 인해 과거에 악몽을 꾸면서 셀 수없이 많은 시간을 변화시켰다.

=========== UPDATE

내가 성공적으로 로그인 내 페이스 북 친구 목록을했습니다. 하지만 이제 문제는 앱을 가지고있는 친구를 나열하고 사진을 나열하는 것입니다. 나는 노력이 :

URL : 저를 줄 OAuthException : An active access token must be used to query information about the current user. 문제를 https://graph.facebook.com/me/friends?friends?fields=id,name,installed,picture

.

API Graph에도 사용해 보았지만 언급하지 않은 오류없이 작동합니다.

내가 단지 me/friends 만 시도하면, 내 친구들이 모두 나열됩니다.

+0

어떻게 가능합니까? 나는 총 친구 수만 얻는다. 덕분에 – Teddy

답변

3

your.m 파일에이 코드를 사용합니다. 매개 변수 안의 필드를 전달해야합니다. 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]; 
4

프로젝트의 Social, Account, SystemConfiguration 프레임 워크를 가져옵니다. 그때 분명히 당신은 URL 내부에 추가 할 수 없습니다, 나는 마침내 그것을 가지고

-(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); 
     } 
    }]; 
} 
+0

. 하지만 점점 페이스 북 친구가 작동하지만 내 문제는 내 페이스 북 애플 리케이션을 설치 한 친구를 받고있다. – HelmiB

+0

https://graph.facebook.com/user_id/friends?fields=id,name,installed URL에서 시도 했습니까? – morroko

+0

OAuthException : 현재 사용자에 대한 정보를 쿼리하려면 활성 액세스 토큰을 사용해야합니다. 문제. 이 오류는 해결을위한 액세스 토큰으로 인해 발생합니다. 액세스 토큰을 가져와야합니다. – morroko