2

異性の友達の情報を取得するために、以下のコードを作成しました。
まず、友達全員のIDを取得するリクエストを送信しました。そして、友達の情報(名前、写真など)を取得するためのリクエストを再度送信しました。
しかし、私には350人の友人がいて、350件のリクエストを送信しました。1分くらいかかるのは本当に遅いです。
プロセスを高速化できますか?

- (void)request:(FBRequest *)request didLoad:(id)result
{
if (request == requestFriends) {
    NSMutableArray *tempKeys = [NSMutableArray array];

    for (NSDictionary *dic in [result objectForKey:@"data"]) {
        [tempKeys addObject:[dic objectForKey:@"id"]];
    }

    NSMutableDictionary *params = [NSMutableDictionary dictionary];

    if ([self.myGender isEqualToString:@"male"]) {
        params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"id,name,gender,age,location", @"field", nil];
    } else if ([self.myGender isEqualToString:@"female"]) {
        params =[NSMutableDictionary dictionaryWithObjectsAndKeys:@"id,name,age,gender,work,school", @"field", nil];
    }

    for (NSString *key in tempKeys) {
        [requestArray addObject: [delegate.facebook requestWithGraphPath:key andParams:params andDelegate:self]];
    }

    i = tempKeys.count;
} else if (request == self.myPicRequest) { //고화질 프로필 사진 받아오는 부분
    NSArray *arr = [result objectForKey:@"data"];
    for (NSDictionary *result in arr) {
        if([[result objectForKey:@"type"]isEqualToString:@"profile"]) {
            profileRequest = [delegate.facebook requestWithGraphPath:[result objectForKey:@"cover_photo"] andDelegate:self]; //프로필의 아이디로 다시 리퀘스트
        }
    }
} else if (request == self.profileRequest) {
    NSURL *url = [NSURL URLWithString:[[[result objectForKey:@"images"] objectAtIndex:3] objectForKey:@"source"]];
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
    CGRect rect = CGRectMake(0, 60, 360, 360); //중간부분을 크롭
    [self.candidatePicArray addObject:[self imageByCropping:image toRect:rect]];
    NSLog(@"이미지들어간다");
} else {         
    for (FBRequest *req in requestArray) {
        if (request == req) {
            if (![[result objectForKey:@"gender"]isEqual:myGender]) {
                [candidateIdArray addObject:[result objectForKey:@"id"]];
                [candidateNameArray addObject:[result objectForKey:@"name"]];

                myPicRequest = [delegate.facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/albums", [result objectForKey:@"id"]] andDelegate:self];

                if ([result objectForKey:@"birth"]) {
                [candidateAgeArray addObject:[result objectForKey:@"birth"]];
                }

                if ([result objectForKey:@"Location"]) {
                [candidateLocationArray addObject:[[result objectForKey:@"Location"] objectForKey:@"name"]]; 
                }

                if ([[result objectForKey:@"work"] objectAtIndex:0]) {
                [candidateWorkArray addObject:[[[[result objectForKey:@"work"] objectAtIndex:0] objectForKey:@"employer"] objectForKey:@"name"]];
                }
                NSLog(@"girl!");
            }
            j++;
//                NSLog(@"candidateNameArray : %@", [result objectForKey:@"name"]);
        }
    }
}

NSLog(@"i = %d, j = %d", i , j);
[progressView setProgress:(float)(j/i) animated:YES]; 

if(i == j) {
    [self performSegueWithIdentifier:@"SEGUE_START" sender:nil];
}

}

4

2 に答える 2

2

すべての友達にリクエストを送信する必要はありません。一度にすべてを行うことができます。

次のようにリクエストしてみてください。

https://graph.facebook.com?ids=iduser1,iduser2,iduser3,iduser4&fields=email,gender,age,name

この方法ははるかに高速です。よろしく

于 2012-04-18T07:59:08.190 に答える
2

SOに関するこの他の質問には、バッチ要求に関するいくつかの手がかりがあります。

FacebookGraphAPIとPHPを使用したバッチ呼び出し

それはphpを使用していますが、いくつかの手がかりを得るかもしれません。

于 2012-04-18T05:47:29.170 に答える