2012-04-20 96 views
8

我试图使用this代码和these instructions做直接消息。发布一个正常的鸣叫工作完全正常,但是当我尝试发送一个直接的消息,我收到了406如何使用iOS 5 Twitter框架发送直接消息?

这是全码:

ACAccountStore *account = [[ACAccountStore alloc] init]; 
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

// 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]; 

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

      // Build a twitter request 
      NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/direct_messages/new.format"]; 
      NSDictionary *p = [NSDictionary dictionaryWithObjectsAndKeys: 
       @"UserName",     @"screen_name", 
       @"Super awsome direct message", @"text", 
       nil 
      ]; 

      TWRequest *postRequest = [[TWRequest alloc] 
       initWithURL: url 
       parameters: p 
       requestMethod: TWRequestMethodPOST 
      ]; 

      // Post the request 
      [postRequest setAccount:acct]; 

      // Block handler to manage the response 
      [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
       NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]); 
       CCLOG(@"Response Data\n%@", responseData); 
       if (!error) 
        CCLOG(@"%@", [error description]); 
      }]; 
     } 
    } 
}]; 
+0

对于fu在接受这篇文章的读者中,当前与Twitter文档无关的版本依赖链接是:https://dev.twitter.com/rest/reference/post/direct_messages/new,它包含当前版本的API @Robin在接受的答案中提到(撰写本文时,1.1:https://api.twitter.com/1.1/direct_messages/new.json)。希望这可以帮助! – 2016-01-14 17:22:10

回答

相关问题