4

次のコードを使用して、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];
          }];
     }
 }];

アプリケーションをテストするために、この方法を 1 か月以上使用していますが、以前は問題なく正常に動作していました。

数週間後、次のメソッドで 403 エラーが返されるようになりました。

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

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

次のエラーが発生します。

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

私はたくさん検索しましたが、この問題の解決策や本当の原因を見つけることができませんでした。

問題を理解するのに役立つかもしれない心に留めておくべきいくつかのメモ:

  • アプリケーションはテストに使用されます。つまり、Twitter 共有を使用し、他のユーザーと多くのことを言及しています。
  • 共有コンテンツは常に同じとは限らないため、タイムラインを頻繁にクリアしていたため、重複の問題は発生しないはずです.

ありがとう

4

3 に答える 3

7

ツイートしようとしているテキストは、以前にツイートしたものと似ている必要があるため、このエラーが発生しています。こちらのドキュメントによると、同じテキストを複数回投稿することはできません。 ここに画像の説明を入力

編集:

また、ウェブサイトに記載されているツイートの総数にも依存する場合があります.

于 2012-12-18T12:00:08.830 に答える
6

アプリケーションをテストするために、この方法を 1 か月以上使用していますが、以前は問題なく正常に動作していました。

そこが問題だと思います。テストしているこのアカウントは、他の人によってスパマーとしてマークされている可能性があります。

別のアカウントまたは別の電話を使用していてコードが機能する場合、それが唯一の説明です。

幸運を

于 2012-12-16T23:35:54.050 に答える
4

次の URL を使用して、ユーザーからのツイートを投稿していることに気付きました。

http://api.twitter.com/1/statuses/update.json

これは Twitter API のバージョン 1.0 を使用していますが、これは非推奨であり、今後数か月でゆっくりと機能しなくなります。

代わりに、使用してみてください

https://api.twitter.com/1.1/statuses/update.json (最近、Twitter API に変更が加えられました。現在は、HTTPS を使用してのみ呼び出すことができます。)

これにより、API の最新バージョンが指定されます。

于 2012-12-15T15:54:46.223 に答える