1
votes

I have integrate twitter api in my application. In my application i have got oauth_token and oauth_secre_key by using oauth library. NOw i want to post a new tweet. How i send my http request with authorization header. my problem is that i have a url for send message from twitter api that is :-https://api.twitter.com/1/statuses/update.json?status=Maybe%20he%27ll%20finally%20find%20his%20keys.%20%23peterfalk&trim_user=true&include_entities=true but when i open i browser then i got this error:-

{"error":"Could not authenticate you.","request":"/1/statuses/update.json?status=Maybe%20he%27ll%20finally%20find%20his%20keys.%20%23peterfalk&trim_user=true&include_entities=true"}

What is the way to fix this error? How i add authorization header with my request?

Thanks in advances...

1

1 Answers

1
votes

I get this error because i have not set parameter in proper format. Now i use this code and working fine.

NSString *trimmedText=[NSString stringWithFormat:@"%@",txt_comment.text];

NSURL *url=[NSURL URLWithString: @"https://api.twitter.com/1/statuses/update.xml"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:trimmedText forKey:@"status"];
NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];

NSData* requestData = [body dataUsingEncoding: NSUTF8StringEncoding];


OAMutableURLRequest *request = [[[OAMutableURLRequest alloc] initWithURL:url consumer: appDelegate.consumer token: appDelegate.accessToken realm: nil signatureProvider: nil] autorelease];  

[request setHTTPMethod:@"POST"];
[request setHTTPBody:requestData];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];

[fetcher fetchDataWithRequest:request
                     delegate:self
            didFinishSelector:@selector(accessTokenTicket_post:didFinishWithData:)
              didFailSelector:@selector(accessTokenTicket:didFailWithError:)];