Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何获得最新的推文?_Iphone_Objective C_Ios5_Twitter - Fatal编程技术网

Iphone 如何获得最新的推文?

Iphone 如何获得最新的推文?,iphone,objective-c,ios5,twitter,Iphone,Objective C,Ios5,Twitter,我试图发布一条推文,然后从时间线上获取最新的推文,并获取我刚刚发布的图像的url 但不知怎么的,它没有给我看最近的那一个。这是我正在使用的代码: -(void)shareButtonClicked:(id)sender { if ([TWTweetComposeViewController canSendTweet]) { // Create account store, followed by a twitter account identifier

我试图发布一条推文,然后从时间线上获取最新的推文,并获取我刚刚发布的图像的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]);
     }];
}
试用http://twitter.com/statuses/user_timeline/ashu1702.json?count=1 在浏览器中,查看发生了什么。我之前误读了你的代码,但现在尝试这个对我来说似乎没问题