gpt4 book ai didi

iphone - 我可以更快地提出请求吗? ( Facebook 图形 API)

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:50:16 25 4
gpt4 key购买 nike

我编写了以下代码来获取我 friend 的异性信息。
首先,我发送了获取所有 friend ID 的请求。然后我再次发送请求以获取 friend 的信息(姓名、照片等)。
但我有 350 个 friend ,我发送了 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];
}

最佳答案

SO 上的另一个问题中有一些关于批处理请求的线索:

Batch calls with Facebook Graph API & PHP

虽然它使用 php,但您可能会得到一些线索。

关于iphone - 我可以更快地提出请求吗? ( Facebook 图形 API),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10203474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com