2012-04-20 11 views
8

मैं सीधे संदेश भेजने के लिए this कोड, और these instructions का उपयोग करने का प्रयास कर रहा हूं। पोस्ट करना एक सामान्य ट्वीट पूरी तरह से ठीक काम करता है, लेकिन जब मैं एक सीधा संदेश भेजने का प्रयास मैं एक 406मैं आईओएस 5 ट्विटर फ्रेमवर्क के साथ सीधा संदेश कैसे भेजूं?

यह पूरा कोड है:

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

फू के लिए के बजाय इस पोस्ट में आने वाले पाठकों को ट्यून करें, ट्विटर डॉक्स के लिए वर्तमान गैर संस्करण-निर्भर लिंक है: https://dev.twitter.com/rest/reference/post/direct_messages/new और इसमें API का वर्तमान संस्करण शामिल है कि @ रोबिन ने स्वीकृत उत्तर में उल्लेख किया है (इस लेखन के रूप में, 1.1: https://api.twitter.com/1.1/direct_messages/new.json)। उम्मीद है की यह मदद करेगा! –

उत्तर

संबंधित मुद्दे