ios - 如何在 iOS 中使用 Twitter/Social 框架获得关注者和关注者
<p><p>如何从用户的 Twitter 帐户中获得所有<strong>关注者</strong>和<strong>关注者</strong>。 </p>
<p>我获得关注者和关注人数。但是我需要关注者和关注用户的用户名。</p>
<p>这是我的代码。</p>
<pre><code>- (void) getAccountInfo
{
ACAccountStore *accountStore = [ init];
ACAccountType *accountType = ;
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted) {
NSArray *accounts = ;
// Check if the users has setup at least one Twitter account
if (accounts.count > 0)
{
ACAccount *twitterAccount = ;
// Creating a request to get the info about a user on Twitter
SLRequest *twitterInfoRequest = parameters:];
;
// Making the request
[twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
// Check if we reached the reate limit
if ( == 429) {
NSLog(@"Rate limit reached");
return;
}
// Check if there was an error
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
}
// Check if there is some response data
if (responseData) {
NSError *error = nil;
NSArray *TWData = ;
// Filter the preferred data
NSString *screen_name = [(NSDictionary *)TWData objectForKey:@"screen_name"];
NSString *name = [(NSDictionary *)TWData objectForKey:@"name"];
int followers = [[(NSDictionary *)TWData objectForKey:@"followers_count"] integerValue];
int following = [[(NSDictionary *)TWData objectForKey:@"friends_count"] integerValue];
}
});
}];
}
} else {
NSLog(@"No access granted");
}
}];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><h2>获取关注者列表</h2>
<p>要获取关注者列表,请将您请求的 <code>URL</code> 更改为:</p>
<pre><code>https://api.twitter.com/1.1/followers/list.json
</code></pre>
<p>它为跟随指定用户的用户返回用户对象的游标集合。</p>
<h2>获取关注用户列表</h2>
<p>要获取您关注的用户列表,请将您请求的 <code>URL</code> 更改为:</p>
<pre><code>https://api.twitter.com/1.1/friends/list.json
</code></pre>
<p>它为指定用户关注的每个用户(也称为他们的“ friend ”)返回用户对象的游标集合。</p>
<p>我使用您的代码对其进行了测试,并且可以正常工作。基于 <a href="https://dev.twitter.com/docs/api/1.1" rel="noreferrer noopener nofollow">REST API v1.1 Resources</a> </p></p>
<p style="font-size: 20px;">关于ios - 如何在 iOS 中使用 Twitter/Social 框架获得关注者和关注者,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/23409101/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/23409101/
</a>
</p>
页:
[1]