के साथ आवृत्ति-सी ब्लॉक का उपयोग करके, इसलिए मैं किसी दिए गए उपयोगकर्ता के लिए सभी अनुयायियों की सूची पुनर्प्राप्त करने के लिए आईओएस 5 में निर्मित ट्विटर एपीआई का उपयोग करने की कोशिश कर रहा हूं। सभी उदाहरण प्रलेखन में मैं पा सकता हूं, जब अनुरोध लौटाता है तो एपीआई पास करने वाले इनलाइन ब्लॉक को निष्पादित करने के लिए अनुरोध किए जाते हैं, जो कि अधिकांश सरल सामग्री के लिए ठीक है, लेकिन जब मैं ~ 1000 अनुयायियों को प्राप्त करने की कोशिश कर रहा हूं, और अनुरोध उन्हें आकार ~ 100 में पर्जित कर रहा है, मैं वापस आने वाले 'अगली पेजिंग पते' का उपयोग करके फिर से अनुरोध को कॉल करने के लिए अटक गया हूं और पूर्णता ब्लॉक के अंदर संसाधित किया गया हूं। यहाँ कोड है:आईओएस ट्विटर एपीआई
- (void)getTwitterFollowers {
// First, we need to obtain the account instance for the user's Twitter account
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType =
[store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user for access to his Twitter accounts
[store requestAccessToAccountsWithType:twitterAccountType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
// The user rejected your request
NSLog(@"User rejected access to his account.");
}
else {
// Grab the available accounts
NSArray *twitterAccounts =
[store accountsWithAccountType:twitterAccountType];
if ([twitterAccounts count] > 0) {
// Use the first account for simplicity
ACAccount *account = [twitterAccounts objectAtIndex:0];
// Now make an authenticated request to our endpoint
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:@"1" forKey:@"include_entities"];
// The endpoint that we wish to call
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/followers.json"];
// Build the request with our parameter
request = [[TWRequest alloc] initWithURL:url
parameters:params
requestMethod:TWRequestMethodGET];
[params release];
// Attach the account object to this request
[request setAccount:account];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (!responseData) {
// inspect the contents of error
FullLog(@"%@", error);
}
else {
NSError *jsonError;
followers = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingMutableLeaves
error:&jsonError];
if (followers != nil) {
// THE DATA RETURNED HERE CONTAINS THE NEXT PAGE VALUE NEEDED TO REQUEST THE NEXT 100 FOLLOWERS,
//WHAT IS THE BEST WAY TO USE THIS??
FullLog(@"%@", followers);
}
else {
// inspect the contents of jsonError
FullLog(@"%@", jsonError);
}
}
}];
} // if ([twitterAccounts count] > 0)
} // if (granted)
}];
[store release];
}
आदर्श रूप में मैं किसी तरह के लिए इस डेटा लौटाए जाने के लिए सुनने चाहते हैं एक अगले पृष्ठ मूल्य के लिए जाँच करें और यदि वह मौजूद है, कोड ब्लॉक पुन: उपयोग और संलग्न डेटा नहीं दिया। मुझे यकीन है कि इसे हासिल करने के लिए 'सर्वश्रेष्ठ अभ्यास' तरीका होना चाहिए, किसी भी मदद की बहुत सराहना की जाएगी!
ऑफटॉपिक: क्या आप "अनुयायियों" का अनुरोध करते हैं जो अनुरोध में उपयोग करते हैं RequestWithHandler विधि ivar? – CarlJ
हां, यह एक 'एनएसएआरएआरई –
है और आपने इसे कहां परिभाषित किया? हेडर फ़ाइल में – CarlJ