I have used Twitter framework provided by Twitter itself for implement 'Login with Twitter' functionality.
As per their documentation, it leverages with Twitter account of iOS system (account that has been configured by user in iOS Settings App). It works fine e.g. if user has configured account in Settings, then it will not ask for credentials. If user has not configured account in Settings, then it will promote login screen. I have no issue with this as far as the flow and my requirement is concerned.
But, if user goes to his/her Twitter account, and revokes access for that APP, then things are not proper for me. I still able to get user details using twitter provided method. Am I missing something that could have been provided by Twitter ?
Here is my code snippet. On successful login, I have called usersShow
method. In that method, I am able to get user data, eventhough user revokes permission for the App from Twitter account (from site). If user has not given permission to the App, then there should be something different I should get. Might be possible that I am missing something.
#pragma mark
#pragma mark - Twitter framework
- (IBAction)btnTwitterLogin_pressed:(id)sender
{
[[Twitter sharedInstance] logInWithCompletion:^
(TWTRSession *session, NSError *error) {
if (session)
{
// This session is then used to make Twitter API requests.
NSLog(@"%@", [session userID]);
NSLog(@"%@", [session userName]);
NSLog(@"%@", [session authToken]);
NSLog(@"%@", [session authTokenSecret]);
[self usersShow:[session userID]];
//[self getUserWithUserID:[session userID]];
}
else
{
NSLog(@"Error: %@", [error localizedDescription]);
}
}];
}
-(void)usersShow:(NSString *)userID
{
NSString *statusesShowEndpoint = kURLTwitterUserInfo;
NSDictionary *params = @{@"user_id": 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) {
// handle the response data e.g.
NSError *jsonError;
NSDictionary *json = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&jsonError];
NSLog(@"%@",[json description]);
// I am being able to get user data here...
}
else {
NSLog(@"Error code: %ld | Error description: %@", (long)[connectionError code], [connectionError localizedDescription]);
}
}];
}
else {
NSLog(@"Error: %@", clientError);
}
}
-(IBAction)btnTwitterLogout_pressed:(id)sender
{
[[Twitter sharedInstance] logOut];
}