1

iOS を使用して Twitter にツイートを投稿しようとしtwitter.framework ていますが、投稿リクエストが完了したときに何らかのエラーが表示されませんが、Twitter には何も投稿されません!

これが私のコードです

-(void)twitPost
{
    ACAccountStore *account = [[ACAccountStore alloc] init];
    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
    if (!arrayOfAccounts)
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Twitter Account" message:@"There are no Twitter accounts configured. You can add or create a Twitter account in the main Settings section of your phone device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];
        return;
    }

    // Request access from the user to access their Twitter account
    [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
     {
         // Did user allow us access?
         if (granted == YES)
         {                 
             // Populate array with all available Twitter accounts
             NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

             if ([arrayOfAccounts count] > 0)
             {
                 // Keep it simple, use the first account available
                 ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

                 TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update.json"] parameters:[NSDictionary dictionaryWithObject:@"This is a sample message!" forKey:@"status"] requestMethod:TWRequestMethodPOST];
                 [postRequest setAccount:acct];

                 // Perform the request created above and create a handler block to handle the response.
                 [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
                  {
                      if(error)
                      {
                          NSLog(@"Twitter Request failed with error: %@",[error localizedDescription]);
                      }else{
                          NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
                          NSLog(@"Message %@",[NSHTTPURLResponse localizedStringForStatusCode:[urlResponse statusCode]]);
                      }
                  }];
             }
         }
     }];
}

ブロック内では、エラーは発生していませんが、これを印刷する必要があります。

2013-09-12 19:51:40.103 MyApp[8380:21603] Twitter 応答、HTTP 応答: 410

2013-09-12 19:51:44.053 MyApp[8380:21603] メッセージが存在しなくなりました

エラーメッセージは記録されません。

ノート、

1) 設定で既に Twitter アカウントを構成していました。

アップデート

ブラウザでリンクしようとするとhttps://upload.twitter.com/1.1/statuses/update.json、次の JSON 応答が出力されます。

{
    errors: [
    {
        message: "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.",code: 68
    } 
    ]
}

どうしたの?何か不足していますか?新しい API に移行する簡単な方法はありますか?

4

1 に答える 1

0

非推奨の Twitter API バージョン 1 を使用しています。

新しいものはここに文書化されています https://dev.twitter.com/docs/api/1.1

作業を容易にするために、 STTwitterなどのサードパーティ ライブラリを確認することをお勧めします。

于 2013-09-13T08:44:01.517 に答える