次のコードを使用して、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 共有を使用し、他のユーザーと多くのことを言及しています。
- 共有コンテンツは常に同じとは限らないため、タイムラインを頻繁にクリアしていたため、重複の問題は発生しないはずです.
ありがとう