我正在尝试发布推文,然后从时间轴中获取最新的推文,并获取刚发布的图片的网址。
但不知怎的,它没有向我展示最近的那个。这是我正在使用的代码:
-(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]);
}];
}
答案 0 :(得分:0)
尝试在浏览器中使用http://twitter.com/statuses/user_timeline/ashu1702.json?count=1
,看看会发生什么。我之前误读了你的代码,但现在尝试这个对我来说似乎没问题。