About Twitter Integration Using OAuth - iphone

I am trying Twitter Integration Using OAuth. Everything is fine but when I compiled and run it gives only a screen which shows my own button and textfield with gray screen, which I hav added in xib, not screen with tweeter.
Here is my code
- (void)viewWillAppear:(BOOL)animated {
if (!self.engine) {
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
self.engine.consumerKey = kOAuthConsumerKey;
self.engine.consumerSecret = kOAuthConsumerSecret;
}
if (![self.engine isAuthorized]) {
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:self.engine
delegate:self];
if(controller) {
[self presentModalViewController:controller animated:YES];
}
}
}

Related

Adding view onto Window of Twitter

Hi i am facing a strange problem. I have a class which is NSObject type, and on same class i want to share image on Facebook and Email and also on Twitter. I successfully done FB and Email, On Email i use [[[UIApplication sharedApplication] keyWindow] addSubview:mailer.view]; to show Mail controller onto Window instread of Presenting Model view controller and same as on Dismiss i use Remove from super view. But when i do same with twitter controller then twitter controller just show me few mili seconds and then hide. I also add new View controller onto Window and then Present its controller onto that View controller but same output. Don't know what going wrong. Please help on that. Thanks in advance. This will be great for me :)
Edited
if (_engine != nil) {
_engine = nil;
[_engine release];
}
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate: self];
if (controller) {
NSLog(#"Sharing on Twitter on loading controller of twitter");
[[UIApplication sharedApplication].keyWindow addSubview:controller.view];
}
else {
NSLog(#"Sharing on Twitter in else condition");
[self sharetoTwitter:screenImg];
}
ShareToTwitterMethod
- (void) sharetoTwitter:(UIImage *)img {
NSString *response = [_engine _uploadImage:img requestType:MGTwitterPublicTimelineRequest responseType:MGTwitterStatus];
NSLog(#"twitter post notification");
}
I used Add subview to load view instead of Presenting View.
Have you tried this
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window addSubView:controller.view];
[window makeKeyAndVisible];//important line dont forget to set this line

Cancel button on MFMessageComposeViewController does not show up

In my iPhone application, I have just implemented in-app SMS functionality. SMS functionality is working fine. But after opening MFMessageComposeViewController, if user wants to cancel sending sms, they have no option. The only option left is to send an sms, then only return on previous view. There should be a cancel button on navigation bar just as it is in the email composer. Below is the line of code that I wrote to have in-app sms functionality:
-(void) smsComposer{
MFMessageComposeViewController *_smsCompose = [[MFMessageComposeViewController alloc] init];
if ([MFMessageComposeViewController canSendText]) {
_smsCompose.body = #"SMS BODY";
_smsCompose.messageComposeDelegate = self;
[self presentModalViewController:_smsCompose animated:YES];
}
}
Is there anything that I am missing?
Thanks in advance,
PC
Try This....
in .h file
#import <MessageUI/MFMessageComposeViewController.h>
and
#interface TestViewController : UIViewController <MFMessageComposeViewControllerDelegate>
And then Button Click method
-(void)buttonPressed:(UIButton *)button
{
[self sendSMS:#"Body of SMS..." recipientList:[NSArray arrayWithObjects:#"+1-111-222-3333", #"111-333-4444", nil]];
}
MFMessageComposeViewController to create the SMS content and another method for handling the user interaction with the SMS dialog.
-(void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = bodyOfMessage;
controller.recipients = recipients;
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
And
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];
if (result == MessageComposeResultCancelled)
NSLog(#"Message cancelled")
else if (result == MessageComposeResultSent)
NSLog(#"Message sent")
else
NSLog(#"Message failed")
}
And remember: You cannot send SMS messages from within the simulator. Test on Device.

How to navigate the view in iphone programming?

In my appController's ViewDidLoad, I have done some thing as below
- (void)viewDidLoad
{
self.overlayViewController =
[[[OverlayViewController alloc] initWithNibName:#"OverlayViewController" bundle:nil] autorelease];
// as a delegate we will be notified when pictures are taken and when to dismiss the image picker
self.overlayViewController.delegate = self;
self.capturedImages = [NSMutableArray array];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// camera is not on this device, don't show the camera button
NSMutableArray *toolbarItems = [NSMutableArray arrayWithCapacity:self.myToolbar.items.count];
[toolbarItems addObjectsFromArray:self.myToolbar.items];
[toolbarItems removeObjectAtIndex:2];
[self.myToolbar setItems:toolbarItems animated:NO];
}
}
I have two methods as below,
- (IBAction)cameraAction:(id)sender
{
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if (self.imageView.isAnimating)
self.imageView.stopAnimating;
if (self.capturedImages.count > 0)
[self.capturedImages removeAllObjects];
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
[self.overlayViewController setupImagePicker:sourceType];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
}
Now as I click the button, the method will launch the class showing custom view, I want to call this without clicking the button, what should I do ?
I wrote the button coding directly in ViewDidLoad, but not working at all
This code, I took from apple's documentation as example
Help !
If I understand correctly, you are wanting to show a view?
If so you could push using:
[self.navigationcontroller pushviewcontroller:YOURVIEWCONTROLLER animated:YES];
Or you could present it using:
[self presentModalViewControllerpushviewcontroller:YOURVIEWCONTROLLER animated:YES];

Implementing Twitter in iPhone using OAuth?

I am trying to implement Twitter in my App using OAuth... I have all the code in my button click method... But as soon as I click on the button my app gets killed on the following line of code
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
There is no message in the debug window except CFrelease... What am I possibly doing wrong?
if(!_engine){
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;
}
if(![_engine isAuthorized]){
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
if (controller){
[self presentModalViewController: controller animated: YES];
}
}
this error shows up
Xcode could not locate source file:
OAMutableURLRequest.m
I use sharekit for all this nonsense. It took me 10 minutes tonight to get a range of service working. getsharekit.com

Error when using Twitter to log in to my iPhone app

I am using Twitter login to enter in my app. But when I click on the Twitter button, the Twitter page opens, but I get the following error:
WHOA there!!! This page is no longer valid.it looks like someone already used the token information you provide.please return to the site tht sent you to this page or try again. it was an probably an honest mistake.
-(void)twitterclick
{
SA_OAuthTwitterEngine *_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]; engine.consumerKey=[[NSString alloc]init];
_engine.consumerSecret=[[NSString alloc]init];
_engine.consumerKey = #"App consumer key";
_engine.consumerSecret = #"App Consumer secret";
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];
if (controller)
[self presentModalViewController:controller animated:YES];
}
How might I resolve this?
I had the same problem... it turned out to be related to the system time on my device.
Not sure how it happened.. but after changing the date, it worked.
your trying to use OAuthData that's too old for use(expired)
in MGTwitterEngine.m look for
`#endif
_secureConnection = YES;
_clearsCookies = NO;`
and change _clearsCookies=YES;
then at the start of your 'twitterClick' put [self clearsCookies]; then the rest of your code
-(void)twitterclick {
[self clearsCookies]; SA_OAuthTwitterEngine *_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self]; engine.consumerKey=[[NSString alloc]init]; _engine.consumerSecret=[[NSString alloc]init]; _engine.consumerKey = #"App consumer key"; _engine.consumerSecret = #"App Consumer secret"; UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self]; if (controller) [self presentModalViewController:controller animated:YES]; }
Just put [_engine setClearsCookies:TRUE] when you are reseting the _engine variable and it should work. That is how I got it to work for me!