Since the twitter api is changed my app no longer posts tweet. Every thing was working fine before and according to new API only request pattern should change ? All the other stuff initialising the engine and rest should be same ?
And the method for sharing should be modified, so I modified it but getting "Bad Authentication 215". All the token info and other things I got it from the authentication header generated from twitter itself:
- (void) shareOnTwitter
{
NSString *urlString = [NSString stringWithFormat:@"https://api.twitter.com/1.1/statuses/update.json"];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:@"check Check CHECK" forKey:@"status"];
[dict setValue:@"-- - - - - -" forKey:@"oauth_consumer_key"];
[dict setValue:@"- - - - - - -" forKey:@"oauth_nonce"];
[dict setValue:@"- - - - - - -" forKey:@"oauth_signature"];
[dict setValue:@"HMAC-SHA1" forKey:@"oauth_signature_method"];
[dict setValue:@"- - - - - - -" forKey:@"oauth_timestamp"];
[dict setValue:@"- - - - - - -" forKey:@"oauth_token"];
[dict setValue:@"1.0" forKey:@"oauth_version"];
NSString *jsonString = [dict JSONRepresentation];
NSData *jsonData = [NSData dataWithBytes:[jsonString UTF8String] length:jsonString.length];
[request setHTTPBody:jsonData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSLog(@"My request...%@", jsonString);
NSData *urlData;
NSURLResponse *response1;
NSError *error = nil;
urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response1 error:&error];
if(error)
{
NSLog(@"Error %@",error);
}
if(!urlData)
{
NSLog(@"No connection!");
}
NSString *responseStr = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@" Twitter : ... %@", responseStr);
}
Twitter explained every thing in its new documentation from Authentication to loads of trivial things but no easy way for previous apps using 1.0 api, how to post a tweet or to upgrade.
Few changes to make it work (works for OAuth):
Open the MGTwitterEngine.m >
Make sure the macros are defined like this:
You will be surprised that
- (void) requestSucceeded: (NSString *) requestIdentifier
and- (void) requestFailed: (NSString *) requestIdentifier withError: (NSError *) error
will be called. But it is pretty easy to put a check that if succeeded is called than don't do anything in failed method.Try below code. Its worked for me :