iOS:使用twitter.framework在Twitter上发布,没有公开对话

时间:2013-09-12 14:28:24

标签: ios twitter twrequest

我正在尝试使用iOS twitter.framework在Twitter上发布推文,不知何故,当发布请求完成时它没有显示任何错误,但是 它没有在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)我已经在设置中配置了一个推特账号。

更新

我尝试在浏览器中链接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?

1 个答案:

答案 0 :(得分:0)

您正在使用已弃用的Twitter API版本1。

这里记录了新的https://dev.twitter.com/docs/api/1.1

您可能需要检查STTwitter等第三方库,以方便您的工作。