Twitter account created with tokens fails on iOS7

南笙酒味 提交于 2019-12-11 02:04:52

问题


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?


回答1:


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?




回答2:


It works on iOS6 and iOS7 by changing the URL to use HTTPS and using API v1.1.



来源:https://stackoverflow.com/questions/19655777/twitter-account-created-with-tokens-fails-on-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!