FacebookIOS图形API中的限制偏移量
我在iOS上遇到一些图形API问题。 我正在尝试从用户处获取所有FB相册。我注意到,默认情况下,graph API首先回答25个元素,然后提供下一个和/或上一个URL来查询其余的元素 我的问题是我需要一次查询每个元素(不仅仅是前25个) 我尝试使用limit参数,正如Facebook文档中所解释的,但我得到了一个空数据数组作为响应。当我删除limit参数时,我可以抓取前25个元素。 当我尝试使用until=today或until=dayed时,Facebook API的行为与此类似 以下是我正在使用的url:FacebookIOS图形API中的限制偏移量,ios,facebook-graph-api,limit,offset,Ios,Facebook Graph Api,Limit,Offset,我在iOS上遇到一些图形API问题。 我正在尝试从用户处获取所有FB相册。我注意到,默认情况下,graph API首先回答25个元素,然后提供下一个和/或上一个URL来查询其余的元素 我的问题是我需要一次查询每个元素(不仅仅是前25个) 我尝试使用limit参数,正如Facebook文档中所解释的,但我得到了一个空数据数组作为响应。当我删除limit参数时,我可以抓取前25个元素。 当我尝试使用until=today或until=dayed时,Facebook API的行为与此类似 以下是我正在
https://graph.facebook.com/me/albums?limit=0
0应该意味着没有限制,我尝试了99999个相同的结果
我想知道是否有人已经从Graph API中获得了这种奇怪的行为
谢谢你的帮助 我终于找到了问题所在 社交网络中有一个bug,它指出苹果总是在url字符串的末尾附加字符串
“?access\u token=[access\u token]”
根据这一点,如果您在URL字符串的前面添加了一个参数,则URL是无效的,因为字符串中有两个“?”
为避免使用NSURLConnection类以这种方式管理连接:
NSString *appendChar = [[url absoluteString] rangeOfString:@"?"].location == NSNotFound ? @"?" : @"&";
NSString *finalURL = [[url absoluteString] stringByAppendingFormat:@"%@access_token=%@", appendChar, self.facebookAccount.credential.oauthToken];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:finalURL]];
NSURLResponse *response;
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error)
[self.delegate facebookConnection:self didFailWithError:error];
else
{
NSError *jsonError;
NSDictionary *resultDictionnary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (jsonError)
[self.delegate facebookConnection:self didFailWithError:jsonError];
else if ([resultDictionnary valueForKey:@"error"])
{
NSDictionary *errorDictionary = [resultDictionnary valueForKey:@"error"];
NSError *facebookError = [NSError errorWithDomain:[errorDictionary valueForKey:@"message"] code:[[errorDictionary valueForKey:@"code"] integerValue] userInfo:nil];
[self.delegate facebookConnection:self didFailWithError:facebookError];
}
else
[self.delegate facebookConnection:self didFinishWithDictionary:resultDictionnary httpUrlResponse:response];
}
首先,我测试字符串中是否存在param字符,并附加正确的字符。
我给你处理错误的方法作为奖励
我仍然使用社交框架获取凭据并连接用户:
NSDictionary *accessParams = @{ACFacebookAppIdKey:kFacebookAppID, ACFacebookPermissionsKey:@[@"email", @"user_photos", @"user_activities", @"friends_photos"]};
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType options:accessParams completion:^(BOOL granted, NSError *error)
{
if (granted)
{
NSArray *facebookAccounts = [accountStore accountsWithAccountType:accountType];
if ([facebookAccounts count] > 0)
{
self.facebookAccount = [facebookAccounts objectAtIndex:0];
self.accessToken = self.facebookAccount.credential.oauthToken;
[self.delegate facebookConnectionAccountHasBeenSettedUp:self];
}
}
else
[self.delegate facebookConnection:self didFailWithError:error];
}];
在这段代码中,我不处理多个facebook帐户,但您可以轻松地转换该代码片段,以自己的方式处理它。此外,连接是同步发送的,因为我使用GCD来避免阻塞接口,但是您可以实现在NSURLConnection类中构建的异步方法
希望这能帮助别人 我只是想说,当我在GraphAPI浏览器中运行URL时,一切都正常。而且凭据是最新的,因为我可以在不使用limit参数的情况下运行查询。。。