我正在创建一个与 Twitter 集成的应用程序 .. 并且想知道如何创建一个按钮以在推文中添加设备的图像。还想知道使用哪个框架以及在哪里代码,因为我的应用程序也应该与 ios4 兼容。
首先,可以在ios5之前在twitter上发送图像吗?
我正在创建一个与 Twitter 集成的应用程序 .. 并且想知道如何创建一个按钮以在推文中添加设备的图像。还想知道使用哪个框架以及在哪里代码,因为我的应用程序也应该与 ios4 兼容。
首先,可以在ios5之前在twitter上发送图像吗?
use sharekit
. Refer ShareKit link.
您可以使用 Oauth 进行此发送。它与 ios4 兼容。acct123 是 Oauth 帐户
- (IBAction)composeTweet:(id)sender
{
// Build a twitter request
NSString *resultprofileUrl= [NSString stringWithFormat:@"https://api.twitter.com/1/statuses/update.json"];
tweets = [NSMutableArray array];
// Posting image and text to twitpic............
ASIFormDataRequest *req = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitpic.com/2/upload.json"]];
[req addRequestHeader:@"X-Auth-Service-Provider" value:@"https://api.twitter.com/1/account/verify_credentials.json"];
[req addRequestHeader:@"X-Verify-Credentials-Authorization"
value:[acct123 oAuthHeaderForMethod:@"GET"
andUrl:@"https://api.twitter.com/1/account/verify_credentials.json"
andParams:nil]];
[req setData:UIImageJPEGRepresentation(imageview3.image, 0.8) forKey:@"media"];
[req setPostValue:@"YourKey" forKey:@"key"];
[req setPostValue:tweetPost.text forKey:@"message"];
[req startSynchronous];
NSLog(@"Got HTTP status code from TwitPic: %d", [req responseStatusCode]);
NSLog(@"Response string: %@", [req responseString]);
NSDictionary *twitpicResponse = [[req responseString] JSONValue];
NSLog(@"image url: %@", twitpicResponse);
url1 = [twitpicResponse valueForKey:@"url"];
NSLog(@"url=%@",url1);
if (url1 == nil) {
url1 = @"";
}
[req release];
NSString *resultUrl = [[NSString alloc]init];
if(reply_tweet_flag != 1)
{
resultUrl = [NSString stringWithFormat:@"%@ %@",tweetPost.text,url1];
}
else
{
resultUrl= [NSString stringWithFormat:@"%@",tweetPost.text];
}
NSLog(@"URL>>>>%@",resultUrl);
NSString *postUrl = @"https://api.twitter.com/1/statuses/update.json";
ASIFormDataRequest *request = [[ASIFormDataRequest alloc]
initWithURL:[NSURL URLWithString:postUrl]];
NSMutableDictionary *postInfo = [NSMutableDictionary
dictionaryWithObject:resultUrl
forKey:@"status"];
for (NSString *key in [postInfo allKeys]) {
[request setPostValue:[postInfo objectForKey:key] forKey:key];
}
[request addRequestHeader:@"Authorization"
value:[acct123 oAuthHeaderForMethod:@"POST"
andUrl:postUrl
andParams:postInfo]];
[request startSynchronous];
NSLog(@"Status posted. HTTP result code: %d", request.responseStatusCode);
if (reply_tweet_flag == 1) {
reply_tweet_flag = 0;
[self refresh];
}
if([tweetPost.text isEqualToString:@""])
{
UIAlertView *message1 = [[UIAlertView alloc] initWithTitle:@""
message:@"Check the message"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[message1 show];
message1.tag=1;
}
else{
[tweetPost setText:@""];
imageview3.image = [UIImage imageNamed:@""];
UIAlertView *message1 = [[UIAlertView alloc] initWithTitle:@""
message:@"Post was send succesfully"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[message1 show];
message1.tag=1;
}
}