How to make Twitter login in iOS APP?
You can use fabric to enable login using Twitter which will enable you a lot more functionalities than authentication like Crashlytics (crash reporting tool)
There are two ways for authentication
1.Log in Button
TWTRLogInButton* logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession* session, NSError* error) {
if (session) {
NSLog(@"signed in as %@", [session userName]);
} else {
NSLog(@"error: %@", [error localizedDescription]);
}
}];
logInButton.center = self.view.center;
[self.view addSubview:logInButton];
2. Log in Method
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
if (session) {
NSLog(@"signed in as %@", [session userName]);
} else {
NSLog(@"error: %@", [error localizedDescription]);
}
}];
Here is the URL for the documentation
iOS twitter login when app is not installed
Add callback URL in this format
twitter-twitterid://
(Replace "twitterid" with "your twitter app id")
Login with twitter always return error
After lot of R&D I got the success. Twitter has made call back url compulsory. I found from this link
You need to add twitterkit-xxxxxxxxxxxxxxxx (twitterkit-consumer key) in call back url at twitter dashboard setting.
I used this method for opening safari (make sure you add safari framework)
TWTRTwitter.sharedInstance().logIn(with: self) { (session, error) in
if (session != nil) {
print("signed in as \(session?.userName ?? "")");
} else {
print("error: \(error?.localizedDescription ?? "")");
}
}
How to implement twitter login functionality on iPhone
Please check the link below each and every step is clearly told by Twitter itself.
https://dev.twitter.com/docs/ios
If you still having problem please follow the link
http://www.raywenderlich.com/5519/beginning-twitter-in-ios-5
That contains the code and all steps !
Hope it will help you !
iOS Login with Twitter
You can either use the Twitter account defined by the user in iOS Settings, or register your own Twitter application on https://apps.twitter.com/.
You can use the third-party library STTwitter in both cases.
How to Authorise User login via twitter in ios
You should use Fabric.io as Larcerax is recommending you. When you install it you will be able to login with twitter really easy. I use these methods:
Login:
- (void)loginWithTwitter {
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session,
NSError *error) {
if (session) {
NSLog(@"signed in as %@", [session userName]);
[[NXTTwitterManager sharedInstance] requestTwtFollowersWithCursor:nil];
[[NXTTwitterManager sharedInstance] requestTwtFollowingWithCursor:nil];
} else {
NSLog(@"error: %@", [error localizedDescription]);
}
}];
}
Get Followers:
- (void)requestTwtFollowersWithCursor:(NSString *)nextCursor {
NSString *statusesShowEndpoint = [NSString
stringWithFormat:@"%@%@",
@"https://api.twitter.com/1.1/followers/ids.json?",
(nextCursor.length > 0)
? [NSString stringWithFormat:@"cursor=%@&count=5000",
nextCursor]
: @"count=5000"];
NSDictionary *params = @{ @"id" : [Twitter sharedInstance].session.userID };
NSError *clientError;
NSURLRequest *request = [[[Twitter sharedInstance] APIClient]
URLRequestWithMethod:@"GET"
URL:statusesShowEndpoint
parameters:params
error:&clientError];
if (request) {
[[[Twitter sharedInstance] APIClient]
sendTwitterRequest:request
completion:^(NSURLResponse *response, NSData *data,
NSError *connectionError) {
if (data) {
NSError *jsonError;
NSDictionary *json =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&jsonError];
[self.followers addObjectsFromArray:json[@"ids"]];
if (![json[@"next_cursor_str"] isEqualToString:@"0"]) {
[[NXTTwitterManager sharedInstance]
requestTwtFollowersWithCursor:
json[@"next_cursor_str"]];
} else {
[self matchFriends];
}
} else {
NSLog(@"Error: %@", connectionError);
[self matchFriends];
}
}];
} else {
NSLog(@"Error: %@", clientError);
}
}
Get Friends (following):
- (void)requestTwtFollowingWithCursor:(NSString *)nextCursor {
NSString *statusesShowEndpoint = [NSString
stringWithFormat:@"%@%@",
@"https://api.twitter.com/1.1/friends/ids.json?",
(nextCursor.length > 0)
? [NSString stringWithFormat:@"cursor=%@&count=5000",
nextCursor]
: @"count=5000"];
NSDictionary *params = @{ @"id" : [Twitter sharedInstance].session.userID };
NSError *clientError;
NSURLRequest *request = [[[Twitter sharedInstance] APIClient]
URLRequestWithMethod:@"GET"
URL:statusesShowEndpoint
parameters:params
error:&clientError];
if (request) {
[[[Twitter sharedInstance] APIClient]
sendTwitterRequest:request
completion:^(NSURLResponse *response, NSData *data,
NSError *connectionError) {
if (data) {
NSError *jsonError;
NSDictionary *json =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&jsonError];
[self.followings addObjectsFromArray:json[@"ids"]];
if (![json[@"next_cursor_str"] isEqualToString:@"0"]) {
[[NXTTwitterManager sharedInstance]
requestTwtFollowingWithCursor:
json[@"next_cursor_str"]];
} else {
[self matchFriends];
}
} else {
NSLog(@"Error: %@", connectionError);
[self matchFriends];
}
}];
} else {
NSLog(@"Error: %@", clientError);
}
}
Related Topics
User Notification Request Always Come with Default Action Identifier
How to Set Uitextview's Height Dynamically in Uitableviewcell Based on String Size
Embedding a Uitableview as a Container View Within a Uiviewcontroller
Uidropinteractiondelegate Performdrop Not Called
Items in File Provider Extension for iOS 11
Setting Uiimageview Image Affects Layout Constraints
What Is Correct Way to Notify View Controller from Appdelegate
Resize Inputaccessoryview Dynamically in iOS 8
How to Store JSON Decodable Values into Coredata Using Swift
How to Use Searchbar for API'S
Skspritenode Does Not Let Touches Pass Through When Isuserinteractionenabled False
Swift 1.2 and Parse: Issue with Retrieving Images to Populate Pfquerycollectionviewcontroller
How to Get Alexa Working on My iOS App
Diffabledatasource: Snapshot Doesn't Reload Headers & Footers
How to Call Rating View from JSON and Show the Rating in My Table View
Icloud Document Picker from Wkwebview Dismissing Container View