簡體   English   中英

如何在iOS5之前在Twitter上發送圖像

[英]how to send image on twitter before ios5

我正在創建一個與Twitter集成的應用程序。我想知道創建按鈕以在推特中添加設備圖像的方法,還想知道在哪個框架中使用它。代碼,因為我的應用程序也應與ios4兼容。

首先,可以在iOS5之前的Twitter上發送圖像嗎?

使用sharekit 請參閱ShareKit鏈接。

  1. 是的,您可以將圖像上傳到Twitter。
  2. 看看這篇關於將Twitter集成到您的應用程序中的博客文章;
  3. 這是關於將twitpic添加到您的應用程序以上傳圖像

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM