使用TWRequest进行Twitter更新会产生403错误

Kas*_*sem 4 iphone twitter objective-c ios ios6

我正在使用以下代码使用iOS 5 twitter API在用户的时间轴上发推文

//创建一个帐户商店对象.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];
          }];
     }
 }];
Run Code Online (Sandbox Code Playgroud)

我一直在使用这种方法一个多月来测试应用程序,它曾经工作正常,没有任何问题.

几周后,它开始在以下方法中返回403错误.

[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
          {

              NSString *output = [NSString stringWithFormat:@"%i", [urlResponse statusCode]];
              [self performSelectorOnMainThread:@selector(TweetStatus:) withObject:output waitUntilDone:NO];
          }];
Run Code Online (Sandbox Code Playgroud)

它给出以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我搜索了很多,找不到任何解决方案或真正的原因来解决这个问题.

请记住一些可能有助于理解问题的注意事项:

  • 该应用程序用于测试,这意味着我们使用了Twitter共享,并提到了很多其他用户.
  • 共享内容并不总是相同,因此不会出现重复问题,因为我们经常清除时间线.

谢谢

Vid*_*thy 7

您尝试发推文的文本必须与之前发布的推文类似,因此您收到此错误.根据此处的文档,相同的文本不能多次发布. 在此输入图像描述

编辑:

它可能还取决于其网站中提到的推文总数.


AlA*_*iri 6

我一直在使用这种方法一个多月来测试应用程序,它曾经工作正常,没有任何问题.

我认为这就是问题所在.您正在测试的此帐户可能被其他人标记为垃圾邮件发送者.

如果您使用其他帐户或其他手机并且代码有效,那么这是我朋友的唯一解释.

祝好运