Sharing a video URL in LinkedIn integration in iPhone - iphone

We can share a message(text) through LinkedIn integration in iPhone Apps. Also, I can share an image Url in LinkedIN ,but Is there any possibility to share a video url through LinkedIn in iPhone Apps......?
Thanks In Advance.....

Use MIS-LinkedIn-Share for sharing url.
Just write following code to share.
- (IBAction)share:(id)sender {
[[MISLinkedinShare sharedInstance] shareContent:self postTitle:#"Title" postDescription:#"Description" postURL:#"http://www.youtube.com/watch?v=_FaWTNEyG80" postImageURL:#"http://www.google.com/images/errors/logo_sm.gif"];
}
don't forget to set api and secret key before sharing.
OR
you can also use method with oAuthStarterkit to share url :-
Here is working code for oAuthStarterKit
1) Open the file OAuthLoginView.m
2) Find the method initLinkedInApi, add your api and secret keys here.
3)Comment lines on viewDidAppear in OAuthLoginView as
- (void)viewDidAppear:(BOOL)animated
{
if ([apikey length] < 64 || [secretkey length] < 64)
{
// UIAlertView *alert = [[UIAlertView alloc]
// initWithTitle: #"OAuth Starter Kit"
// message: #"You must add your apikey and secretkey. See the project file readme.txt"
// delegate: nil
// cancelButtonTitle:#"OK"
// otherButtonTitles:nil];
// [alert show];
// [alert release];
//
// // Notify parent and close this view
// [[NSNotificationCenter defaultCenter]
// postNotificationName:#"loginViewDidFinish"
// object:self
// userInfo:self.profile];
// [self dismissModalViewControllerAnimated:YES];
}
[self requestTokenFromProvider];
}
- (void)shareImp
{
NSLog(#"share Imp called ");
NSURL *url = [NSURL URLWithString:#"http://api.linkedin.com/v1/people/~/shares"];
OAMutableURLRequest *request =[[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:self.accessToken
callback:nil
signatureProvider:nil];
NSMutableDictionary *contents=[[NSMutableDictionary alloc] init];
[contents setValue:#"description goes here" forKey:#"description"];
[contents setValue:#"www.google.com" forKey:#"submitted-url"];
[contents setValue:#"title goes here" forKey:#"title"];
[contents setValue:#"http://economy.blog.ocregister.com/files/2009/01/linkedin-logo.jpg" forKey:#"submitted-image-url"];
NSMutableDictionary *visible=[[NSMutableDictionary alloc] init];
[visible setValue:#"anyone" forKey:#"code"];
NSMutableDictionary *updatedic=[[NSMutableDictionary alloc] init];
[updatedic setObject:visible forKey:#"visibility"];
[updatedic setObject:contents forKey:#"content"];
[updatedic setValue:#"Check out the LinkedIn Share API!" forKey:#"comment"];
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:updatedic forKey:#"share"];
[archiver finishEncoding];
[archiver release];
NSLog(#"post dictionary is %#",updatedic);
NSData *postData=[NSData dataWithData:data];
[request setValue:#"json" forHTTPHeaderField:#"x-li-format"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:[NSString stringWithFormat:#"%d",[postData length]] forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:postData];
[request setHTTPMethod:#"POST"];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:#selector(postUpdateApiCallResult:didFinish:)
didFailSelector:#selector(postUpdateApiCallResult:didFail:)];
[request release];
}
- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
NSLog(#"did finish called ");
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSLog(#"response body after posting is %#",responseBody);
[responseBody release];
[self dismissModalViewControllerAnimated:YES];
}
- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
NSLog(#"%#",[error description]);
}

By using Sharekit frame work we are able to post the video URL in LinkedIn.for that we can pass url as a string,
SHKItem *shareItem = [SHKItem text:text];
[SHKLinkedIn shareItem:shareItem];

Related

how to show activity indicator in iphone application while uploading data

I am uploading data to server i want that when i click upload button then activity indicator should start and stop after the data is uploaded.
This is how i am uploading data but activity indicator not working.
-(IBAction)startSyncButtonAction{
[self startActivity];
CereniaAppDelegate *appDelegate = (CereniaAppDelegate *)[[UIApplication sharedApplication] delegate];
for (int i=0; i<[appDelegate.coffeeArray count]; i++) {
Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];
int mycount=[appDelegate.coffeeArray count];
NSLog(#"My Array count is %d",mycount);
NSString*device_Id=coffeeObj.device_Id;
NSString*R1=coffeeObj.R1;
NSString*R2=coffeeObj.R2;
NSString*R3=coffeeObj.R3;
NSString*R4=coffeeObj.R4;
NSString*R5=coffeeObj.R5;
NSString*R6=coffeeObj.R6;
NSString*R7=coffeeObj.R7;
NSString*R8=coffeeObj.R8;
NSString*R9=coffeeObj.R9;
NSString*R10=coffeeObj.R10;
NSString*R11=coffeeObj.R11;
NSString*R12=coffeeObj.R12;
NSString*R13=coffeeObj.R13;
NSString*R14=coffeeObj.R14;
NSString*update_date_time=coffeeObj.update_date_time;
NSString*teritory1=coffeeObj.teritory;
int mycount1=[appDelegate.coffeeArray count];
NSLog(#"My Array After delete is %d",mycount1);
NSLog(#"device_Id%#",device_Id);
NSLog(#"R1%#",R1);
NSLog(#"R2%#",R2);
NSLog(#"R3%#",R3);
NSLog(#"R4%#",R4);
NSLog(#"R4%#",R5);
NSLog(#"R4%#",R6);
NSLog(#"R4%#",R7);
NSLog(#"R4%#",R8);
NSLog(#"R4%#",R9);
NSLog(#"R4%#",R10);
NSLog(#"R4%#",R11);
NSLog(#"R4%#",R12);
NSLog(#"R4%#",R13);
NSLog(#"R4%#",R14);
NSLog(#"update_date_time%#",update_date_time);
NSString *post =[[NSString alloc] initWithFormat:#"device_Id=%#&R1=%#&R2=%#&R3=%#&R4=%#&R5=%#&R6=%#&R7=%#&R8=%#&R9=%#&R10=%#&R11=%#&R12=%#&R13=%#&R14=%#&update_date_time=%#&teritory1=%#",device_Id,R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,update_date_time,teritory1];
NSLog(post);
NSURL *url=[NSURL URLWithString:#"http://celeritas-solutions.com/pah_brd_v1/pfizersurvey/SyncSurveySTD.php"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(#"%#",data);
}
for (int i=0; i<[appDelegate.coffeeArray count]; i++) {
Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:i];
[appDelegate removeCoffee:coffeeObj];
}
}
-(void)startActivity:(id)sender
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
activityImageView.hidden=NO;
activityView.hidden=NO;
[activityView startAnimating];
[pool release];
}
Try below code but I am giving example you should modify it & use according to your need:
alert= [[UIAlertView alloc] initWithTitle:#"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];
Use this line to dismiss indicator:
[alert dismissWithClickedButtonIndex:0 animated:YES];
Try. Best of luck.
For better user experience i will recommend you to use UIProgressHUD
UIProgressHUD* hud = [[UIProgressHUD alloc] initWithFrame:CGRectZero];
[hud setText:#"Loading, please wait."];
[hud showInView:someView];
...
[hud done];
...
[hud hide];
...
[hud release];
Are you 100% sure that activityView is not nil?? I don't see anywhere you set it to anything. Also, even it were not nil, have you added it to a view? activityView is just a regular UIView, it won't automatically appear in UIWindows.

POST username and password in JSON

I have a web service I am working with a url such as
//myurl/index.jsp?user_name=bob&user_pwd=new
as you can see the username has been set as "bob" and password "new". The site give this json file when entered,
[{"success":"1"}]
How do you implemented it on xcode, where when a user enters "bob" as username and "new" as password it should lead to the next controller. How do can I achieve that ?
I followed this tutorial though it's not quite the same, how do you do this. Thanks.
Use a navigation controller and set you view controller as the rootViewController. Then after the user has entered the credentials push the new view controller onto the navigation stack.
Get the value of success from json response. If it is equal to 1 then push to next controller else do nothing.
In Following code you can pass data by either GET or POST method … use any one (As You Wish)
-(void) sendRequest
{
//////////////////////////// GET METHOD /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
NSString *strURL=[NSString stringWithFormat:#"http://myurl/index.jsp?user_name=bob&user_pwd=new"];
self.request=[NSURLRequest requestWithURL:[NSURL URLWithString:strURL]];
self.nsCon=[[NSURLConnection alloc] initWithRequest:request delegate:self];
//////////////////////////// POST METHOD /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
NSString *postString = [NSString stringWithFormat:#"&user_name=bob&user_pwd=new"];
NSString *url = [NSString stringWithFormat:#"http://myurl/index.jsp/"];
self.request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.request setHTTPMethod:#"POST"];
[self.request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(self.nsCon)
{
self.receivedData=[[NSMutableData alloc] init];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error",#"") message:NSLocalizedString(#"Not Connected !!",#"") delegate:nil cancelButtonTitle:NSLocalizedString(#"OK",#"") otherButtonTitles:nil];
[alert show];
[alert release];
}
}
#pragma mark -
#pragma mark - Connection Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[self.responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[GeneralClass stopHUD];
NSLog(#"Connection failed.");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error",#"") message:NSLocalizedString(#"Connection failed!",#"") delegate:nil cancelButtonTitle:NSLocalizedString(#"OK",#"") otherButtonTitles:nil];
[alert show]; alert = nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseString = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
NSMutableDictionary *receivedData = [responseString JSONValue];
if([[receivedData objectForKey:#"success"] isEqualToString:#"1"])
{
MainDetailViewController *mdController = [[MainDetailViewController alloc] init];
[self.navigationController pushViewController:mdController animated:YES];
}
else
{
NSLog(#"%#",receivedData);
}
}
Post login data
NSString *soapMsg = [NSString stringWithFormat:#"&data={\"LoginUser\":[{\"UserName\":\"%#\",\"Password\":\"%#\"}]}",firstname.text, password.text];
NSHTTPURLResponse *response;
NSData *myRequestData = [ NSData dataWithBytes: [ soapMsg UTF8String ] length: [ soapMsg length ] ];
NSString *postLength = [NSString stringWithFormat:#"%d", [myRequestData length]];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:#"http://myurl/index.jsp"]];
[request setHTTPMethod: #"POST" ];
[request setHTTPBody: myRequestData ];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody: myRequestData];
NSURLConnection *myConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
Receive and vaild json data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:WebXmlData encoding:NSUTF8StringEncoding];
NSDictionary *results = [responseString JSONValue];
BOOL success = [[results objectForKey:#"success"] boolValue];
if (success) {
ViewController *viewController =[[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
}
}
Not quite the answer you are looking for but this is more a recommendation for what should you use.
I use github link for Network related activities.
They have nice documentation and very easy to use (uses blocks)
NSDictionary *paramsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:#"user",#"client_id",#"password",#"new", nil];
[[YourAFHttpClientExtenstion sharedInstance] postPath:LOGIN_PATH parameters:paramsDictionary success:^(AFHTTPRequestOperation *operation, id responseObject) {
//handle success
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// handle error.
}];
YourAFHttpClientExtenstion is extending AFHttpClient and adds a convening method of shared instance and implements initWithBaseUr:

how to send image on twitter before ios5

I'm creating an application that has integration with Twitter .. and wanted to know what have to do to create a button to add an image of the device in the tweet.and also wanted to know which framework to use it and also where the code because my app should be compatible with ios4 too.
First of all is it possible to send image on twitter before ios5?
Yes you can upload image to twitter.
Have a look at this blog article on integrating twitter into your applications; and
This one about adding twitpic to your application to upload images
use sharekit. Refer ShareKit link.
You can use Oauth for this sending.it is compatible with ios4.acct123 is Oauth account
- (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;
}
}

Uploading video on YouTube

I need to upload video from my iphone app to youtube, i have got the access token form google oauth but getting problem while uploading video to youtube, for post request to upload video i am using ASIFormDataRequest. Below is my code, please help me to resolve my mistake, thanks in advance.
- (IBAction)buttonTouched:(id)sender
{
NSLog(#"%d %#",[sender tag],[[NSUserDefaults standardUserDefaults] valueForKey:#"access_token"]);
progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30, 90, 200, 20.0)];
[alertView addSubview:progressView];
[alertView show];
[progressView setProgress:0];
NSString *name=[videosToShow objectAtIndex:[sender tag]];
NSString *newFilePath = [NSString stringWithFormat:#"%#.mov", [self.path stringByAppendingPathComponent:name]];
NSLog(#"Content URL :%#;", newFilePath);
NSURL *url = [NSURL URLWithString:#"https://uploads.gdata.youtube.com/feeds/api/users/default/uploads"];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setRequestMethod:#"POST"];
NSLog(#"Auth Token== %#",[[NSUserDefaults standardUserDefaults] valueForKey:#"access_token"]);
[request setPostValue:[[NSUserDefaults standardUserDefaults] valueForKey:#"access_token"] forKey:#"authentication_token"];
[request setPostValue:devKey forKey:#"developer_key"];
[request setPostValue:#"abcabc" forKey:#"boundary_string"];
[request setPostValue:devKey forKey:#"content_length"];
NSString *path = [[NSBundle mainBundle] pathForResource:#"xmlcontent" ofType:#"txt"];
NSString *strXml = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[request setPostValue:strXml forKey:#"API_XML_Request"];
[request setPostValue:#"video/mov" forKey:#"video_content_type"];
[request setPostValue:#"video/mov" forKey:#"Binary File Data"];
[request setFile:newFilePath withFileName:#"1.mov" andContentType:#"video/mov" forKey:#"uploaded"];
[request setUploadProgressDelegate:self];
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestFinished:)];
[request setDidFailSelector:#selector(requestFailed:)];
[request setShowAccurateProgress:YES];
[request startAsynchronous];
}
- (void)requestFinished:(ASIFormDataRequest *)request {
[alertView dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Congrats!!!" message:#"File has been downloaded."
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)requestFailed:(ASIFormDataRequest *)request1 {
NSError *error = [request1 error];
NSLog(#"%#", error);
}
Below is the file xmlcontent.txt
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Bad Wedding Toast</media:title>
<media:description type="plain">
I gave a bad toast at my friend's wedding.
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>toast, wedding</media:keywords>
</media:group>
</entry>
Below is the error that i am getting
Error Domain=ASIHTTPRequestErrorDomain Code=3 "Authentication needed"
UserInfo=0x1c8ed0 {NSLocalizedDescription=Authentication needed}
You are using the GData library but haven't linked/added it. Check out GData Objective-C Client Setup in XCode 4 on how to build/link the GData library correctly.

How to twit a picture with some text in iPhone

I want to know that is there any way I can post picture in twitter with some text, some one has suggested to use "http://tinyurl.com/".I don't know where to start, in my previous application I twit successfully but that only contains text.
A proper direction to proceed would be a great help.
There are a couple of ways. I would suggest you use ShareKit. It does most of the work for you.
To post image to twitter we have to first post the image to twit pick and then we have to send that url to twitter that is the process to send image to twitter this is the sample code to send image to twitter..........
NSString *postUrl = #"https://api.twitter.com/1/statuses/update.json";
ASIFormDataRequest *request = [[ASIFormDataRequest alloc]
initWithURL:[NSURL URLWithString:postUrl]];
NSMutableDictionary *postInfo = [NSMutableDictionary
dictionaryWithObject:statusText.text
forKey:#"status"];
NSLog(#"%#",postInfo);
NSString *str1= statusText.text;
NSLog(#"Status posted. HTTP result code: %d", request.responseStatusCode);
[request release];
[statusText resignFirstResponder];
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:[oAuth oAuthHeaderForMethod:#"GET"
andUrl:#"https://api.twitter.com/1/account/verify_credentials.json"
andParams:nil]];
[req setData:UIImageJPEGRepresentation(imageView.image, 0.8) forKey:#"media"];
// Define this somewhere or replace with your own key inline right here.
[req setPostValue:#"74734e805f2ad85afae441ca12c16087" forKey:#"key"];
[req startSynchronous];
NSLog(#"Got HTTP status code from TwitPic: %d", [req responseStatusCode]);
NSLog(#"Response string: %#", [req responseString]);
NSDictionary *twitpicResponse = [[req responseString] JSONValue];
NSLog(#"%#",[[req responseString] JSONValue]);
textView.text = [NSString stringWithFormat:#"Posted image URL: %#", [twitpicResponse valueForKey:#"url"]];
NSString *str=[NSString stringWithFormat:#" %#",[twitpicResponse valueForKey:#"url"]];
NSLog(#"%#",str);
if([str isEqualToString:#" (null)"])
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Message" message:#"Could not authenticate you(header rejected by twitter)" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];
}
else
{
NSString *postUrl = #"https://api.twitter.com/1/statuses/update.json";
ASIFormDataRequest *request = [[ASIFormDataRequest alloc]
initWithURL:[NSURL URLWithString:postUrl]];
NSString *txtmessage=[str1 stringByAppendingString:str];
/*NSMutableDictionary *postInfo = [NSMutableDictionary
dictionaryWithObject:[twitpicResponse valueForKey:#"url"]
forKey:#"status"];*/
NSMutableDictionary *postInfo = [NSMutableDictionary
dictionaryWithObject:txtmessage
forKey:#"status"];
for (NSString *key in [postInfo allKeys]) {
[request setPostValue:[postInfo objectForKey:key] forKey:key];
}
[request addRequestHeader:#"Authorization"
value:[oAuth oAuthHeaderForMethod:#"POST"
andUrl:postUrl
andParams:postInfo]];
[request startSynchronous];
if(request.responseStatusCode!=200)
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Message" message:#"Already posted" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];
}
else {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Message" message:#"sucess" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];
}
NSLog(#"Status posted. HTTP result code: %d", request.responseStatusCode);
statusText.text = #"";
[request release];
[statusText resignFirstResponder];
}