Как получить самый актуальный твит? - PullRequest
0 голосов
/ 23 ноября 2011

Я пытаюсь опубликовать твит, а затем получить последние твиты с временной шкалы и получить URL-адрес только что отправленного изображения.

Но почему-то он не показывает мне последний.Это код, который я использую:

-(void)shareButtonClicked:(id)sender
{
    if ([TWTweetComposeViewController canSendTweet]) 
    {
        // Create account store, followed by a twitter account identifier
        // At this point, twitter is the only account type available
        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
                     UIImage * image = [UIImage imageNamed:@"welcomescreen-header.png"];
                     NSString * status = @"This is welcome screen.";
                     NSString * completeHandle = [NSString stringWithFormat:@"%@@%@",status,twitterHandle.text];

                     NSData * data=[completeHandle dataUsingEncoding:NSUTF8StringEncoding];
                     NSLog(@"Text:%@",completeHandle);
                     NSData * imageData = (UIImageJPEGRepresentation(photo.image, 90));


                     TWRequest *postRequest = [[TWRequest alloc] initWithURL:
                                               [NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"] 
                                                                  parameters:nil requestMethod:TWRequestMethodPOST];
                     [postRequest addMultiPartData:imageData withName:@"media" type:@"image/jpeg"];
                     [postRequest addMultiPartData:data withName:@"status" type:@"text"];

                     // 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]);
                          if ([urlResponse statusCode] == 200) {
                              [self getTheUserTimeLine];

                          }
                      }];
                 }
             }
         }];
    }
}

-(void)getTheUserTimeLine

{
    TWRequest *postRequest = [[TWRequest alloc] initWithURL:
                              [NSURL URLWithString:@"https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=ashu1702&count=1"] 
                                                 parameters:nil requestMethod:TWRequestMethodGET];

    // Block handler to manage the response
    [postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) 
     {
         if ([urlResponse statusCode] == 200) 
         {
             // The response from Twitter is in JSON format
             // Move the response into a dictionary and print
             NSError *error;        
             NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
             NSLog(@"Twitter response: %@", [dict description]);                           
         }
         else
             NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
     }];
}

1 Ответ

0 голосов
/ 23 ноября 2011

Попробуйте использовать http://twitter.com/statuses/user_timeline/ashu1702.json?count=1 в своем браузере и посмотрите, что произойдет.Раньше я неправильно читал ваш код, но, пробуя это сейчас, мне кажется, это нормально.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...