2012-04-20 6 views
8

私はthisコードを使用しようとしており、these instructionsは直接メッセージを送信しようとしています。通常のつぶやきを投稿すること完全​​に正常に動作しますが、私はダイレクトメッセージを送信しようとすると、私が手406iOS 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)。お役に立てれば! –

答えて

関連する問題