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 回答