Error creating twitter ACAccount on iOS5: NSURLErrorDomain error -1012 - iphone

I am having trouble creating and saving a new twitter account to ACAccountStore on iOS5.
After performing all the steps to init the account, ACAccountStore's saveAccount:withCompletionHandler: returns NSURLErrorDomain error -1012.
Does anyone have similar issues?
My code sample below is using requestToken to init ACAccountCrendential. This object is an OAToken (ShareKit object) initialized with the token and secret received from twitter after completing OAuth.
ACAccountStore *store = [[[ACAccountStore alloc] init] autorelease];
ACAccountType *twitterAccountType = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
ACAccount *account = [[[ACAccount alloc] initWithAccountType:twitterAccountType] autorelease];
account.username = #"twitterusername";
account.credential = [[[ACAccountCredential alloc] initWithOAuthToken:requestToken.key tokenSecret:requestToken.secret] autorelease];
[store requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error) {
if (granted) {
[store saveAccount:account withCompletionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(#"TWITTER ACCOUNT CREATED SUCCESSFULLY!");
}
else{
NSLog(#"ERROR creating twitter account: %#", [error description]);
}
}];
}
}];
The strange thing is that Apple's Accounts Framework Reference suggests that saveAccount:withCompletionHandler: attempts to perform OAuth itself:
If the account type supports authentication and the account is not authenticated, the account is authenticated
using its credentials. If the authentication is successful, the account is saved; otherwise, it is not saved.
I find that very strange since there is no way for the user to authenticate directly with the server by inputting username/password.
I also tried to initialize ACAccountCredential with my application's consumer key and consumer secret, with the same result (failed with NSURLErrorDomain error -1012.)
Any guidance on this topic would be greatly appreciated!
thanks.

I'm having the same trouble adding a Twitter account with ACAccount. However, I was able to create a Twitter account with ACAccount successfully using an authorized OAuth Access token and Access token secret, not the Consumer key and Consumer secret. (dev.twitter.com/apps->Twitter->OAuth->OAuth Setting-->Access token and Access token secret) This means that you still have to use an OAuth library to get an authorized Access token and Access token secret when the user is adding a Twitter account.
Update: You can see how Twitter recommends that you migrate existing accounts to iOS5 system accounts here. That link provided me with the best example of how to add an ACAccount.

Related

Azure mobile: Client-directed login operation error (Facebook)

I am trying to use "Client-directed login operation" to authorize users with Facebook account on my azure-mobile service (http://msdn.microsoft.com/en-us/library/windowsazure/jj710106.aspx)
I downloaded and configured iOS Facebook SDK for the project;
Here is the code for user login:
NSArray* permissions = #[#"email, user_about_me, basic_info"];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession* session, FBSessionState status, NSError* error) {
if (!error) {
[_msClient loginWithProvider:provider
token:#{#"access_token" : [[session accessTokenData] accessToken]}
completion:^(MSUser* user, NSError* error) {
NSLog(#"%#", error);
}];
}
}];
This code returns error:
Error Domain=com.Microsoft.WindowsAzureMobileServices.ErrorDomain Code=-1302 "Error: The Facebook Graph API access token authorization request failed with HTTP status code 400" UserInfo=0x1768ba80 {NSLocalizedDescription=Error: The Facebook Graph API access token authorization request failed with HTTP status code 400}
I can confirm, that
NSString* access_token = [[session accessTokenData] accessToken];
returns a valid access token, because it works here https://developers.facebook.com/tools/explorer/?method=GET&path=me without any errors.
What am I doing wrong?
Had a similar problem and I can confirm that the error returned by Azure Mobile Service is most unhelpful. I eventually read up about what's happening under the hood here: https://developers.facebook.com/docs/facebook-login/access-tokens/#extending
Then I tried to acquire the long-lived token by invoking a GET request manually (https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id={app-id}&client_secret={app-secret}&fb_exchange_token={short-lived-token}) and here I finally got the real error message. In my case it turned out to be "The request is invalid because the app is configured as a desktop app" and simply flipping a switch in the Facebook app configuration fixed it.
In your case it might be a different error message, but I suggest you take this approach and see where it takes you.
This is old now but just had the same issue. Check that you don't have the "Is Your App Secret Embedded" switched on in. I had it on because I thought the ZUMO SDK would have it somewhere, but I guess it just lives on the cloud in your MS identity configuration.

Getting error ACErrorPermissionDenied (error code 7) for Facebook when using Social Framework

I am fetching the user’s Facebook account ID and name using ACAccountStore.
When an alert comes up asking the user for permission (“XYZ would like to access your news feed and profile”) and the user taps on “Don’t Allow”, I get error code 7, i.e ACErrorPermissionDenied.
But after that, if I go to Settings and switch on the Facebook settings for my app and back in the app the alert pops up again and the user taps on “OK”, I’m still getting error code 7 (ACErrorPermissionDenied). So it’s enabled in Settings and I’ve tapped “OK” in the app, but it’s still giving me this error.
If the first time I allow access and after that switch access on or off from Settings, it gives me the proper error or success. This problem occurs only if the user taps “Don’t Allow” the first time. If he doesn’t allow it in the app when it asks, then he will not be able to allow FB access to my app.
I’ve tested this on iOS 6.0 and 6.0.1 using the following code:
NSMutableArray *acAccountArray = [[NSMutableArray alloc] init];
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType =
[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore
requestAccessToAccountsWithType:accountType
options:[self getOptionDictionary:ACAccountTypeIdentifierFacebook permission:[[NSArray alloc]initWithObjects:#"read_stream",#"user_about_me",#"email", nil]]
completion:^(BOOL granted, NSError *error) {
if(granted) {
// Doing what I want
} else {
NSLog(#"Error: %#", error);
}
}];
-(NSDictionary *)getOptionDictionary:(NSString * const)accountTypeIdentifier
permission:(NSArray*)permissionArray {
NSDictionary *options = nil;
if (accountTypeIdentifier == ACAccountTypeIdentifierFacebook) {
options = #{
#"ACFacebookAppIdKey" : #"dhksadhakjdhkshd",
#"ACFacebookPermissionsKey" : permissionArray,
#"ACFacebookAudienceKey" : ACFacebookAudienceFriends};
}
return options;}
Is your app still in "sandbox mode" on Facebook? If yes, it will be visible only to administrators and developers. If you're logged in to Facebook on your device with a non-administrator for your app, you might receive this error. Disabling the sandbox mode fixed the problem for me.
This is because you have removed your app in facebook, even i am facing same problem. If you try to login using any method other than iOS native login then it adds facebook app if it is not there or removed by the user in facebook settings but it is currently not happening if you try to login using iOS native login.
Please inform me if you come across ant solution for this issue and also is their a way i can remove my app being listed in iOS facebook settings in this case because if i remove and then user retries for login then it works correctly.

twitter update using TWRequest gives 403 error

i'm using the following code to tweet in user's timeline using the iOS 5 twitter API
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if(granted)
{
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:buttonIndex];
// Create a request, which in this example, posts a tweet to the user's timeline.
// This example uses version 1 of the Twitter API.
// This may need to be changed to whichever version is currently appropriate.
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:#"hello this is a tweet" forKey:#"status"] requestMethod:TWRequestMethodPOST];
// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];
// Perform the request created above and create a handler block to handle the response.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
NSString *output = [NSString stringWithFormat:#"%i", [urlResponse statusCode]];
[self performSelectorOnMainThread:#selector(TweetStatus:) withObject:output waitUntilDone:NO];
}];
}
}];
i've been using this method for more than a month now for testing the application and it used to work fine with no problems.
few weeks a goo it started to return a 403 error in the following method.
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
NSString *output = [NSString stringWithFormat:#"%i", [urlResponse statusCode]];
[self performSelectorOnMainThread:#selector(TweetStatus:) withObject:output waitUntilDone:NO];
}];
it gives the following error:
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x1f8b3250 {NSErrorFailingURLKey=http://api.twitter.com/1/statuses/update.json, NSErrorFailingURLStringKey=http://api.twitter.com/1/statuses/update.json, NSUnderlyingError=0x1ed19f90 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012
i've searched a lot and could not find any solution or real cause to this problem.
a few notes to keep in mind that might help understanding the problem:
the application is used for testing which means that we used the twitter sharing and mentions a lot with other users.
the sharing content is not always the same so no duplication issue should occur as we were clearing the timeline frequently.
thanks
The text you have been trying to tweet must be similar to what has been tweeted by you previously, hence you are getting this error. According to the documentation here, the same text cannot be posted more than once.
EDIT:
It might also depend on the total number of tweets as mentioned in their website.
i've been using this method for more than a month now for testing the application and it used to work fine with no problems.
I think that's the issue right there. this account you are testing might been marked as a spammer by other people.
If you use another account or other phone and the code works, then that's the only explanation my friend.
Good luck
I noticed you are using the following URL to post a tweet from your user:
http://api.twitter.com/1/statuses/update.json
This is using version 1.0 of the Twitter API which is deprecated and slowly will stop working over the next few months
Instead you should try using
https://api.twitter.com/1.1/statuses/update.json (There has been a recent change to the Twitter API. You can now only call it using HTTPS.)
This will specify the latest version of the API.

Retrieve Facebook Account Information in ios 6

i want retrieve the information of a facebook account on the ios 6 integrated Facebook, now i do it in this way and i can retrieve only the username:
ACAccountType *accountTypeF = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
NSArray *accountsArray = [accountStore accountsWithAccountType:accountTypeF];
ACAccount *facebookAccount = [accountsArray objectAtIndex:0];
if (facebookAccount.username) {
}
}
}];
i want know how i can retrieve also the Name and Surname of the account and the pic of the user...anyone can help me?
Jeffrey is right. Go to this post: Facebook iOS 6 - get user info and implement 2 methods given by Daniel.
After then make sure to make some changes in your application settings on facebook developer account.
On main settings page disable sandbox mode
Put your applications bundle id
Enable facebook login
Then go to Advance settings on the left
Select Native/Desktop as App Type
make sure App secret in client is NO
Save all settings and it really takes few minutes to populate the changes on server. Finally Must reset you simulator
ACAccount is a generic "social" class provided by Apple; it has only limited account information and no knowledge of Facebook data. After obtaining the account, you can instantiate an SLRequest to query the Facebook Graph API, using the account to authenticate it...
NSURL* URL = [NSURL URLWithString:#"https://graph.facebook.com/me"];
SLRequest* request = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:URL
parameters:nil];
[request setAccount:account]; // Authentication - Requires user context
[request performRequestWithHandler:^(NSData* responseData, NSHTTPURLResponse* urlResponse, NSError* error) {
// parse the response or handle the error
}];

TWTweetComposeViewController cansendtweet is true even when user revoked app in twitter

IOS 5.x using the TWTweetComposeViewController class. All is well even with the
if ( [TWTweetComposeViewController canSendTweet] )
UNLESS the user revokes access for the app on twitter, then the above is still true and when trying to send a tweet an error message appears with
Cannot be sent because the connection to Twitter failed.
This can be fixed if the user goes to SETTINGS / TWITTER / USERNAME
A message will come up
The user name of password is incorrect.
If the password is retyped, the app will be re authenticated on twitter and all is good again.
1) Is there anyway to capture the error under program control and then can inform the user to redo the settings?
2) How come the canSendTweet is true even when the app has been revoked?
1) No as it's a system level issue so not something you can control or manage directly from you apps sandbox
2) canSendTweet merely confirms that twitter is accessible on that device and that an account has been set up. It's not intended to identify if the user has given you access to their twitter account.
If you want to know if your app can access the users twitter you should use:
- (void)requestAccessToAccountsWithType:(ACAccountType *)accountType
withCompletionHandler:(ACAccountStoreRequestAccessCompletionHandler)handler;
located in the Accounts Framework
#import <Accounts/Accounts.h>
As an example this is one way of doing it:
accountStore = [[ACAccountStore alloc] init];
twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:twitterAccountType
withCompletionHandler:^(BOOL granted, NSError *error) {
if (!granted) {
// Access denied by the user - do what you need to do
NSLog(#"Authenticated : User rejected access to his account.");
}
else {
// Access granted
// Do what you want here to send the tweet or whatever
}
}];
This issue can also be caused by having the time and date of your device set to a time other than the current time. Twitter will not allow you to authenticate from the Settings app in this case, and it also causes the TWTweetComposeViewController to fail with the "connection to Twitter failed" error message, even though canSendTweet returns true.