Getting the list of followers from twitter sdk using fabric but not able to get more than 20. And another limitation is need to get the all followers first and then upload to api. I am using code below to get the followers list. Please guide wha changes need to make in existing code or need to shift to some new way.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted) {
//[MBProgressHUD showHUDAddedTo:self.view animated:YES];
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
// Check if the users has setup at least one Twitter account
if (accounts.count > 0)
{
ACAccount *twitterAccount = [accounts objectAtIndex:0];
// Creating a request to get the info about a user on Twitter
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:#"https://api.twitter.com/1.1/followers/list.json"] parameters:[NSDictionary dictionaryWithObject:twitterAccount.username forKey:#"screen_name"]];
[twitterInfoRequest setAccount:twitterAccount];
// 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 ([urlResponse statusCode] == 429) {
NSLog(#"Rate limit reached");
return;
}
if (error) {
NSLog(#"Error: %#", error.localizedDescription);
return;
}
// Check if there is some response data
if (responseData) {
NSError *error = nil;
NSArray *TWData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
// Filter the preferred data
NSArray *arrFollowList = [TWData valueForKey:#"users"];
// Filter the preferred data
NSMutableArray *arrFollowersList = [[NSMutableArray alloc]init];
for(int i =0; i<[arrFollowList count]; i++)
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:[[arrFollowList objectAtIndex:i] valueForKey:#"name"] forKey:#"FriendName"];
[dict setObject:#"" forKey:#"Email"];
[dict setObject:strType forKey:#"FriendType"];
[dict setObject:[[arrFollowList objectAtIndex:i] valueForKey:#"id"] forKey:#"UserAccountId"];
//[dict setObject:#"" forKey:#"UserAccountId"];
[dict setObject:#"1" forKey:#"Team_Id"];
[dict setObject:[[arrFollowList objectAtIndex:i] valueForKey:#"profile_image_url"] forKey:#"ProfileImage"];
[arrFollowersList addObject:dict];
}
NSString *teamId = #"1";
NSDictionary *objDict = [NSDictionary dictionaryWithObjectsAndKeys:
teamId, #"Team_Id",
arrFollowersList, #"userFriendList",
nil];
NSLog(#"dict %#",objDict);
[iOSRequest postData:[NSString stringWithFormat:#"%#", kFriendListUpdateUrl] :objDict :^(NSDictionary *response_success)
{
NSLog(#"response_success:%#", response_success);
if([[response_success valueForKey:#"message"] isEqualToString:#"Success"])
{
NSMutableDictionary *dictSquads = [[NSMutableDictionary alloc]init];
[dictSquads setObject:[standardDefaults valueForKey:#"UserId"] forKey:#"User_Id"];
[dictSquads setObject:#"1" forKey:#"Team_Id"];
[dictSquads setObject:strType forKey:#"FriendType"];
}
}
:^(NSError *response_error)
{
}];
}
});
}];
}
} else {
NSLog(#"No access granted");
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}
}];
Related
I am trying to load the tweets through json since I am currently making an twitter app. No sign of getting data from json twitter. I also have an null output from my array as well. Is there a possible mistake that I made using the API?
-(void)twitterTimeLine{
ACAccountStore *account = [[ACAccountStore alloc]init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted == YES) {
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
ACAccountType *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestAPI = [NSURL URLWithString:#"https://api.twitter.com/1.1/statuses/home_timeline/json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init];
[parameters setObject:#"100" forKey:#"count"];
[parameters setObject:#"1" forKey:#"include_entities"];
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = (ACAccount *)twitterAccount;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[posts performRequestWithHandler:^(NSData *response, NSHTTPURLResponse *urlResponse, NSError *error){
array=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
// NSLog(#"%#",posts);
NSLog(#"%#",array);
NSLog(#"---------");
if (array.count !=0) {
dispatch_async(dispatch_get_main_queue(),^{
[timelineTableView reloadData];
});
}
}];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
else {
NSLog(#"%#", [error localizedDescription]);
}
};
}];
Try this :
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
This might be the reason of getting warning.
Update your URL with :
https://api.twitter.com/1.1/statuses/home_timeline.json
I would like to get user profile information using SLRequest in twitter?
Currently I am coding like
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com/1.1/users/show.json"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:#"ali",#"screen_name",nil];
account = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *twitterAccounts = [account accountsWithAccountType:twitterAccountType];
// Runing on iOS 6
if ([LoginViewController isTwitterAvailable])
{
NSLog(#"In the IFF...... ");
[account requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *error)
{
NSLog(#"in body ");
if (granted)
{
NSLog(#"in granted ..");
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:params];
[request setAccount:[twitterAccounts lastObject]];
dispatch_async(dispatch_get_main_queue(), ^
{
[NSURLConnection sendAsynchronousRequest:request.preparedURLRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response1, NSData *data, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^
{
if (data)
{
//NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ;
//NSLog(#"data:%#",string);
NSError* error;
NSDictionary* dicUser = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&error];
It returns the whole of the info, not profile info,
How can I get profile info of user who is getting sign in ?
Thanks
Try folowing code giving from one of the live project, you can modify as per your existing structure. Let me know in case of any problem.
_accountStore = [[ACAccountStore alloc] init]; //Declare accountStore as property and initialize
ACAccountType *accountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[_accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted){
NSArray *accounts = [_accountStore accountsWithAccountType:accountType];
if (accounts.count > 0){
ACAccount *twitterAccount = [accounts lastObject];
NSDictionary *dict1 = [twitterAccount dictionaryWithValuesForKeys:[NSArray arrayWithObject:#"properties"]];
NSDictionary *properties = dict1[#"properties"];
NSDictionary *returnDict = #{#"TwitterID":properties[#"user_id"],#"UserName":twitterAccount.username};
NSLog(#"Profile details->%#",properties);
}else{
NSMutableDictionary* details = [NSMutableDictionary dictionary];
[details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
error = [NSError errorWithDomain:#"Domain" code:error.code userInfo:details];
NSLog(#"Error occured->%#",error.localizedDescription);
}
} else {
NSMutableDictionary* details = [NSMutableDictionary dictionary];
if(error.code == ACErrorAccountNotFound){
[details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
}else if(error.code == ACErrorPermissionDenied || error.code == ACErrorAccessDeniedByProtectionPolicy) {
[details setValue:kTwitterAccessDeniedMsg forKey:NSLocalizedDescriptionKey];
}else {
[details setValue:kTwitterErrorMsg forKey:NSLocalizedDescriptionKey];
}
error = [NSError errorWithDomain:#"Domain" code:error.code userInfo:details];
NSLog(#"Error occured->%#",error.localizedDescription);
}
}];
Few macros
#define kTwitterErrorMsg #"Please set your Twitter account in Settings."
#define kTwitterAccessDeniedMsg #"Twitter Access denied."
I'm trying to get the user's Twitter timeline using the Twitter API in iOS SDK and got an error saying:
code = 92; message = "SSL is required";
I googled the error and I found this page on the Twitter API website, but I have no idea how to use it in iOS.
Here's my code:
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted == YES){
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestAPI = [NSURL URLWithString:#"http://api.twitter.com/1.1/statuses/user_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:#"100" forKey:#"count"];
[parameters setObject:#"1" forKey:#"include_entities"];
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = twitterAccount;
[posts performRequestWithHandler:
^(NSData *response, NSHTTPURLResponse
*urlResponse, NSError *error)
{
// The NSJSONSerialization class is then used to parse the data returned and assign it to our array.
array = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
if (array.count != 0) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"%#",array);
});
}
}];
}
} else {
// Handle failure to get account access
NSLog(#"%#", [error localizedDescription]);
}
}];
Is there a way to solve this problem?
Use "https" in your URL:
https://api.twitter.com/1.1/statuses/user_timeline.json
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
I have recently begun an Xcode project, and it requires me to get the feed, or timeline, from a Twitter account. I am following this tutorial. Although when I compile my code, it has no errors, it does not log any tweets. I also downloaded the source code for the project, but it still returns nothing. I realize that it could be a problem from my account, but I have tweeted something recently, followed some people, retweeted, basically everything you could do to update a timeline! Thanks for the help!
Twitter Account:#Pushahk
-(void)getTwitterFeed{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted == YES) {
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestAPI = [NSURL URLWithString:#"http://api.twitter.com/1.1/statuses/user_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:#"100" forKey:#"count"];
[parameters setObject:#"1" forKey:#"include_entities"];
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = twitterAccount;
[posts performRequestWithHandler:
^(NSData *response, NSHTTPURLResponse
*urlResponse, NSError *error)
{
// The NSJSONSerialization class is then used to parse the data returned and assign it to our array.
self.TwitterPosts = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"Hi");
for (int i = 0; i < [self.TwitterPosts count]; i++) {
NSLog(#"%#", [self.TwitterPosts objectAtIndex:i]);
NSLog(#"Hi");
}
});
}];
}
}
else{
NSLog(#"%#", [error localizedDescription]);
}
}];
}
It's because include_entities is no longer a valid parameter within the v1.1 API (it was in the v1 API). You may also need to provide a screen name, as I believe setting the .account property on the request is only for OAuth purposes.
Source: http://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
I am trying to make a function which returns a list of twitter users but I am not able to make the function return a nsmutablearray. Here it is the code I execute
-(NSMutableArray*) getTwitterUsersInPosition: (Position*) position
{
// Request access to the Twitter accounts
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted) {
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
// Check if the users has setup at least one Twitter account
if (accounts.count > 0)
{
ACAccount *twitterAccount = [accounts objectAtIndex:0];
// Creating a request to get the info about a user on Twitter
NSArray *keys = [NSArray arrayWithObjects:#"geocode", #"count", nil];
NSArray *objects = [NSArray arrayWithObjects:#"37.781157,-122.398720,100mi", #"2", nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects
forKeys:keys];
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:#"https://api.twitter.com/1.1/search/tweets.json"] parameters:dictionary];
[twitterInfoRequest setAccount:twitterAccount];
// Making the request
[twitterInfoRequest performRequestWithHandler: ^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
// Check if we reached the rate limit
if ([urlResponse statusCode] == 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 = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
NSMutableArray *usersArray= [[NSMutableArray alloc] init];
NSMutableArray* statuses= [(NSDictionary *) TWData objectForKey:#"statuses"];
for (NSDictionary* dict in statuses )
{
NSString* user = [[dict objectForKey:#"user"] objectForKey:#"screen_name"];
NSLog(#"%#",user);
[usersArray addObject:user];
}
return userArray; //Here it says "Return type 'NSMutabelArray *' must match previous type 'void' when block literal has unspecified return type
}
});
}];
}
} else {
NSLog(#"No access granted");
}
}];
}
Thanks for your help.
Your method can NOT have a return type because the value you want to return is obtained asynchronously and isn't available until after the method has completed.
You need to rewrite your method so that it returns the data:
To a delegate
Via a block
Into an instance variable and triggers some update
Via a notification
Basically some mechanism that allows you to deal with the asynchronous response. Please don't make the call synchronous.
In the middle of your code you simply write return without a value (as if your method has return type of void):
if ([urlResponse statusCode] == 429) {
NSLog(#"Rate limit reached");
return;
}
// Check if there was an error
if (error) {
NSLog(#"Error: %#", error.localizedDescription);
return;
Change it to return nil and the code should compile.