我正试图贴上前线,然后从时间表中拿到最新的信条,并找到刚刚张贴的图像。
但有些人却不向我表明最近的情况。 这部法律正在使用:
-(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]);
}];
}