[英]Twitter.framework Image and message issue
我正在使用Twitter.framework將帶有消息的圖像發布到Twitter。 但是我在Twitter帳戶中看到沒有消息的圖像。 我用這個代碼
// Create an account store object.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
// Create an account type that ensures Twitter accounts are retrieved.
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
UIImage *image =[UIImage imageNamed:@"logo"];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"https://upload.twitter.com/1/statuses/update_with_media.json"]
parameters:[NSDictionary dictionaryWithObjectsAndKeys:@"Hello. This is a tweet.", @"status", @"My message", @"message", nil] requestMethod:TWRequestMethodPOST];
// "http://api.twitter.com/1/statuses/update.json"
[postRequest addMultiPartData:UIImagePNGRepresentation(image) withName:@"media" type:@"multipart/png"];
// Set the account used to post the tweet.
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
NSLog(@"output = %@\n\n", output);
}];
}
}
}];
我在推特上看到的是:
當我展開時:
但是我沒看到消息
請嘗試使用它並使其正常運行。 希望它也會對您有幫助
-(IBAction)goTweet:(id)sender{
if ([TWTweetComposeViewController canSendTweet])
{
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
[tweetSheet setInitialText:[NSString stringWithFormat:@"YOUR TWEET HERE"]];
[tweetSheet addImage:[UIImage imageNamed:@"site-logo.jpg"]];
[self presentModalViewController:tweetSheet animated:YES];
[shareLoading stopAnimating];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter"
message:@"Sorry, you can't send a Tweet yet, please make sure you are connected to the internet and have at least one Twitter account set up on your phone in Settings --> Twitter."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
我發現,如何使用圖像發送文本:添加此代碼
[postRequest addMultiPartData:[@"This photo is taken with my iPhone using nPassword!" dataUsingEncoding:NSUTF8StringEncoding] withName:@"status" type:@"multipart/form-data"];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.