How to renew request access to Twitter account again in iOS? - ios

I request access to Twitter account by this code:
-(void)requestAccessToTwitterAccounts{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted)
{
NSLog(#"Granted");
_twAccounts = [accountStore accountsWithAccountType:accountType];
if (_twAccounts.count > 0){
NSLog(#"%#",_twAccounts);
} else {
NSLog(#"No Accoutn");
}
} else{
NSLog(#"Not Grand");
}
}];
}
The problem is that I call this method again when user choose "Don't Allow" but it just work OK 1time.
1st time, it ask for permission, if user choose "Don't Allow", the asking alert view not display again. I just see the log "Not Grand".
How can we renew request access to twitter again so that the alertView for permission display again?

I think you only can say (message if there are no access) user to allow app to use twitter again in twitter section in settings app.

Go to settings and enable Allow these apps to use your account switch for respective application Manually. Once you tapped Don't allow then the switch become off. Make the user to enable the Switch.

As par My Knowledge this is Not Possible once use can select "Don't Allow" that not asking again. This is a same like Address-book Permission Alert or Location Permission.
So you can set Manually Alert Massage for allow Access From setting and that need Manually open Setting view and Logged in From there.

Related

Programatically fetch value of "Allow these Apps to use your account" in Twitter

I want to programatically fetch the value of "Allow these Apps to use your account" in Twitter Settings Page and if it is disabled open the Settings Page so the user can manually change the value.
I have tried to open settings page in Twitter in iOS 8.1 using the code :
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#”prefs:root=TWITTER”]];
But it does nothing in iOS 8+.Does anyone know how to fetch this value programatically and redirect to Settings Page of twitter ?
prefs scheme does not work anymore, all your app can do now is open an app preferences via UIApplicationOpenSettingsURLString constant. see this answer.
Note also, that requestAccessToAccountsWithType:options:completion: method will trigger a permission dialog if this is a first call. So the better way will be to fail gracefully, when you try to do something with twitter. The permissions dialog should be a result of user action, so it will not be confusing for him.
Try Following...
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil
completion:^(BOOL granted, NSError *error)
{
if (granted == YES)
{
NSLog(#"Twitter Access");
}
else
{
NSLog(#"No Twitter Access");
}
}];

How to request Facebook publish_actions permission during login in iOS

To request facebook publish_actions permission during login in android I do
loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setPublishPermissions(“publish_actions”);
loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
FacebookOptInFragment.this.user = user;
updateUI();
}
});
That’s all I need to do and I am done. User will first login and then get prompted to grant publishing permission. How do I do the exact same thing in iOS?
Note that I just now downloaded the Facebook SDK, which means I have the latest and greatest (in case that is relevant).
Some documentation first
Requesting publishing permissions with publish_actions during login
creates a second step in the login UI. So you should request minimum
read permissions during login then request any additional or publish
permissions when someone actually needs them. To optimize your
permission requests, see Optimizing Permissions.
So If all you need is to authorize your iOS app and grant publish_actions permission and if you really want integrate with iOS Facebook account, you have to ask for reading permission before you ask for the publishing permission. See the Request at Login portion of the page link above for getting read permissions.
Then you can request additional permissions for publish_actions like
// Request publish_actions
[FBSession.activeSession requestNewPublishPermissions:[NSArray arrayWithObject:#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
__block NSString *alertText;
__block NSString *alertTitle;
if (!error) {
if ([FBSession.activeSession.permissions
indexOfObject:#"publish_actions"] == NSNotFound){
// Permission not granted, tell the user we will not publish
alertTitle = #"Permission not granted";
alertText = #"Your action will not be published to Facebook.";
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertText
delegate:self
cancelButtonTitle:#"OK!"
otherButtonTitles:nil] show];
} else {
// Permission granted, publish the OG story
[self publishStory];
}
} else {
// There was an error, handle it
// See https://developers.facebook.com/docs/ios/errors/
}
}];
Check this portion of the docs for permission management as well

Login with twitter in ios 7

I am doing login functionality.
In which -
user will give twitter email id to login and if login gets succeeded, my app will navigate user to its inner screen of my app.
If user has configured twitter account from user's device ios settings. My app takes user's email id from there and it will navigate
into second screen of my app.
If user has not configured twitter account from ios settings then, if user tapps a button login with twitter from my app login screen, it
will navigate user to the twitter page from where user has to give
email id (twitter id) and password and if login is successful it
should back to my app's inner screen(same functionality as like login
with facebook).
how could I achieve this. Thanks in advance.
First of all, you can not get user email address from twitter's API either using iOS7 framework or Twitter's Native API.
If you want to get user email address you can ask user to enter it manually. That's what Twitter people say in their API Docs. For your Point 2 and 3 here is the sample code using iOS7 way
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) // check Twitter is configured in Settings or not
{
self.accountStore = [[ACAccountStore alloc] init]; // you have to retain ACAccountStore
ACAccountType *twitterAcc = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[self.accountStore requestAccessToAccountsWithType:twitterAcc options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
self.twitterAccount = [[self.accountStore accountsWithAccountType:twitterAcc] lastObject];
NSLog(#"Twitter UserName: %#, FullName: %#", self.twitterAccount.username, self.twitterAccount.userFullName);
[self getTwitterEmail]; // here you can ask user to enter email address. Its up to you how you ask user about it. Either in alert View or in Text Field.
}
else
{
if (error == nil) {
NSLog(#"User Has disabled your app from settings...");
}
else
{
NSLog(#"Error in Login: %#", error);
}
}
}];
}
else
{
NSLog(#"Not Configured in Settings......"); // show user an alert view that Twitter is not configured in settings.
}

Save Facebook account using ACAccountStore

I'm trying to use iOS Social.framework to share to Facebook. However, most users will not have Facebook setup in Settings>Facebook so therefore Facebook doesn't show up when you bring up a UIActivityViewController, it just isn't listed. (See UIActivity with no settings for Facebook or just google "facebook doesn't show in UIActivityViewController," there's plenty of people trying to solve this problem.)
Our app already uses the Facebook SDK so I can get at the Facebook account info, so I thought I would just get the info and then save the info in Settings>Facebook. Here's my code. (Which I got from When do we use saveAccount:(ACAccount *)account of ACAccountStore class? and iOS requestAccessToAccountsWithType is Not Showing Permission Prompt / NSAlert)
- (void)storeAccountWithAccessToken:(NSString *)token secret:(NSString *)secret {
if (self.accountStore == nil) {
self.accountStore = [[ACAccountStore alloc] init];
}
//We start creating an account by creating the credentials object
ACAccountCredential *credential = [[ACAccountCredential alloc] initWithOAuthToken:token tokenSecret:secret];
ACAccountType *acctType =[self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
ACAccount *newAccount = [[ACAccount alloc] initWithAccountType:acctType];
//Here we assign credentials and now can save account
newAccount.credential = credential;
NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
[VVEnvironment stringForKey:kVVEnvironmentKeyFacebookAppID], (NSString *)ACFacebookAppIdKey,
[NSArray arrayWithObject:#"basic_info"], (NSString *)ACFacebookPermissionsKey,
ACFacebookAudienceEveryone, (NSString *)ACFacebookAudienceKey,
nil];
[_accountStore requestAccessToAccountsWithType:acctType options:options completion:^(BOOL granted, NSError *error) {
if (granted == YES) {
[self.accountStore saveAccount:newAccount withCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"the account was saved!");
}
else {
if ([error code] == ACErrorPermissionDenied) {
NSLog(#"Got a ACErrorPermissionDenied, the account was not saved!");
}
NSLog(#"the account was not saved! %d, %#", [error code], error);
}
}];
}
else {
NSLog(#"ERR: %# ",error);
}
}];
}
I added the call to requestAccessToAccountsWithType there because without I was getting a ACErrorPermissionDenied back from saveAccount. When I run this I do see my app slide briefly aside for the Facebook dialog (if I delete my app on Facebook's website it does bring up the full dialog asking me for permissions which I grant.)
The problem is that granted is always NO, so I never get a chance to save the account. What am I missing here?
I am running this on a real device that has the Facebook App installed and setup.
I'd appreciate any help on this, thanks!
There is no solution available for this. iOS native facebook applications are not allowed to write or save account to ACAccountStore. It only allow to access account from the ACAccountStore. iOS only allow to store 1 facebook account at a time. Try to do these steps you will understand this easily,
Add a facebook account to settings App and try to get permission to access it. It will grand permission.
Remove account and try to get the permission it will deny access.
Add a facebook account and get access and try to save new account to ACAccountStore, It will say that Native applications are not allowed to save account to ACAccountStore.
The proposed solution is, Add the account to settings App and login with it and Share using Social framework or presentOSIntegratedDialog.

Multiple Prompts for iOS Facebook Account Access

I am attempting to add facebook integration into a project. In iOS 6+, I request access to the user's facebook accounts with the following code.
if (self.accountStore == nil) self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountTypeFacebook = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[self.accountStore requestAccessToAccountsWithType:accountTypeFacebook options:options
completion:^(BOOL granted, NSError *error) {
if(granted) {
self.accountsArray = [self.accountStore accountsWithAccountType:accountTypeFacebook];
dispatch_sync(dispatch_get_main_queue(), ^{
[self updateTable:self.accountsArray];
});
} else {
NSLog(#"error: %#",error);
}
}];
If the user selects "cancel" in the modal popup that prompts for access to Facebook accounts, is it possible to prompt the user again the next time the app needs this access?
Currently, if the user first selects "cancel", the user must then go into the Settings app and manually change the permission to use facebook within the app. I am not attempting to change this permission directly, I just want to prompt the user for access multiple times.

Resources