2012-11-20 49 views

回答

-1

使用他们的ID作为参数,直接发送邮件到您的追随者:

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.json"]; 

      NSMutableDictionary *params; 

      for (int i =0 ; i <[friends_SelectedIDArray count]; i++) { 

       params = [[NSMutableDictionary alloc] init]; 
       //[params setObject:@"@meenukatal" forKey:@"screen_name"]; 
       [params setObject:[friends_SelectedIDArray objectAtIndex:i] forKey:@"user_id"]; 
       //need to change sendimg message every time do not send same message // 

       [params setObject:text_Field.text forKey:@"text"]; 

       TWRequest *postRequest = [[TWRequest alloc] 
              initWithURL: url 
              parameters: params 
              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]); 
        NSLog(@"Response Data\n%@", responseData); 

        if ([urlResponse statusCode] == 200) { 

         UIAlertView *alertmessage = [[UIAlertView alloc]initWithTitle:@"Message" message:@"You have successfully posted the message! " delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
         [alertmessage show]; 

        } 

        else { 

         UIAlertView *alertmessage = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"There might be some problem please try later! " delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
         [alertmessage show]; 

        } 


        if (!error) 
         NSLog(@"%@", [error description]); 
       }]; 
      } 
     } 
    } 
}]; 
+0

他询问让他们,而不是送他们。 – jpswain

相关问题