2012-04-20 19 views
8

Doğrudan iletileri yapmak için this kodunu ve these instructions kullanmaya çalışıyorum. Normal bir tweet gönderme mükemmel çalışıyor, ancak doğrudan bir mesaj göndermeye çalıştığımda olsun bir 406iOS 5 Twitter Framework ile doğrudan bir mesaj nasıl gönderirim?

Bu tam kodudur:

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

yerine Bu yazının karşısına çıkan okuyucular, Twitter dokümanlar için mevcut olmayan sürüm bağımlı bağlantı: https://dev.twitter.com/rest/reference/post/direct_messages/new ve API'nın güncel sürümünü içerir. @Robin kabul edilen cevapta bahsetti (bu yazıdan itibaren 1.1: https://api.twitter.com/1.1/direct_messages/new.json). Bu yardımcı olur umarım! –

cevap

İlgili konular