-1

我正在创建一个与 Twitter 集成的应用程序 .. 并且想知道如何创建一个按钮以在推文中添加设备的图像。还想知道使用哪个框架以及在哪里代码,因为我的应用程序也应该与 ios4 兼容。

首先,可以在ios5之前在twitter上发送图像吗?

4

3 回答 3

1

use sharekit. Refer ShareKit link.

于 2012-11-19T05:32:22.400 回答
1
  1. 是的,您可以将图像上传到 Twitter。
  2. 查看这篇关于将 twitter 集成到您的应用程序中的博客文章;和
  3. 这一篇关于将 twitpic 添加到您的应用程序以上传图像
于 2012-11-19T10:01:52.510 回答
0

您可以使用 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;
}

}

于 2012-11-19T07:43:31.870 回答