iostwitterios7acaccount

Twitter account created with tokens fails on iOS7


I am working on an app running on iOS6/7, with custom views to post on Twitter. To improve user experience, if no system accounts are available, I would present the user with a webview to enter their credentials, store them in the ACAccountStore as suggested in ACAccountCredential.h and use it to post.

It works great on iOS6 but on iOS7 sharing fails with 401 error. The weird thing is that the account is saved with no errors in the ACAccountStore and can be used by the Twitter app to read and post on Twitter (with no further login), so I assume the account (token and token secret) is working properly.

SLRequest *postRequest = nil;
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"];
NSDictionary *content = @{@"status":self.textToShare};
postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:url
parameters:content];

[postRequest setAccount:self.twitterAccount];
[postRequest performRequestWithHandler:completionHandler];

I tried also with API v1.1 but it does not seem to help. Any ideas?


Solution

  • This problem will occur on iOS6 as well as iOS7, since /1/statuses/update.json is now deprecated. Also, beginning with v1.1 of the API, you must use HTTPS for all requests.

    Your URL should be changed to the following:

    NSURL *url = [NSURL URLWithString:
                  @"https://api.twitter.com/1.1/statuses/update.json"];
    

    For more information, please see Twitter API FAQ: What does the retirement of API v1 entail?