objective-c : Twitter login error on iPad : Whoa there - objective-c

I've been using the classic Ben Gottlieb Twitter Open Source project to create a twitter login for iPad.
My code to instantiate the engine and display the login controller is:
if (!_engine) {
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
[_engine setConsumerKey:#"kConsumerKey"];
[_engine setConsumerSecret:#"kConsumerSecret"];
}
if (![_engine isAuthorized]){
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
if (controller){
if ([controller respondsToSelector:#selector(setModalPresentationStyle:)] == YES) {
controller.modalPresentationStyle = UIModalPresentationFormSheet;
}
[self presentModalViewController:controller animated:YES];
return;
}
}
In addition, I set the URLS for SA_OAuthTwitterEngine to https:
self.requestTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/request_token"];
self.accessTokenURL = [NSURL URLWithString: #"https://twitter.com/oauth/access_token"];
self.authorizeURL = [NSURL URLWithString: #"https://twitter.com/oauth/authorize"];
and my TWITTER_DOMAIN in MGTwitterEngine.m has been changed to:
#define TWITTER_DOMAIN #"api.twitter.com/1"
Running this code in the simulator for both iPhone and iPad works like a charm. HOWEVER, whenever I test this code on an iPad device, I'm thrown this error:
Whoa there! The request token for this page is invalid. It may have
already been used, or expired because it is too old. Please go back to
the site or application that sent you here and try again; it was
probably just a mistake
(Screenshot attached).
Any suggestions on how to get the standard login screen to appear will be greatly appreciated

I had the same problem and tried Jeff's way. It didn't work either. For some unknown reason, check your time settings and set to automatically set the time. This worked for me.

I ran into the same issue. What happens is that the request doesn’t get a request token. You can explicitly call that:
SA_OAuthTwitterEngine *myEngine;
[myEngine requestRequestToken];
Hope this helps!

Related

Facebook Invite VC displaying weird

I am having a problem using the new Facebook SDK invite system. The view controller which appears when using FBSDKAppInviteDialog displays very oddly, then disappears before the user has time to interact with it.
FBSDKAppInviteContent *content =[[FBSDKAppInviteContent alloc] init];
content.appLinkURL = [NSURL URLWithString:#"http://example.com"];
//content.appInvitePreviewImageURL = [NSURL URLWithString:#"https://www.example.com/my_invite_image.jpg"];
FBSDKAppInviteDialog *inviteDialog = [[FBSDKAppInviteDialog alloc] init];
if ([inviteDialog canShow]) {
inviteDialog.content = content;
inviteDialog.delegate = self;
[inviteDialog show];
}
This is what appears on the screen when the modal launches:
Does anyone know of any reason this would happen?
Edit[Sep 8, 2015 15:15 EDT]: We are currently getting an error code of 1; unknown error. Here is the exact print out:
Failed to perform app invite: The operation couldn’t be completed. (com.facebook.Facebook.platform error 1.)
Full Report => {
}
We thought it might be that we don't have friend permissions or something to do with iOS 9; however we are running our test on iOS 8, and we added friend permissions, and we have not seen a change.
I would call the validateWithError function they provided. It might give an idea of what the issue is.
FBSDKAppInviteDialog documentation

Open OneNote from my Ipad Application - Need OneNote URL SCHEME?

When I use onenote:// for opening OneNote from my ipad Application, it opens OneNote but gives an error message that says
Cannot Open Link" There’s a problem with this link in One Note.
This is my Code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"onenote://"]];
PS: OneNote for Ipad already has to be installed in the Ipad Device before trying this.
Is this the right URL SCHEME for OneNote - onenote://
Or am I doing it wrong.
The Error Message does note create a problem when closed, but I just want to get rid of the Error Message.
Also can parameters be passed to OneNote from my Application.
Help Appreciated!!
Using "onenote-cmd://" should open up OneNote without any errors.
The reason you're getting an error is that the iOS OneNote client doesn't support being launched by a protocol handler without having parameters completed for notebook, section, and page (it doesn't know where to navigate to).If you're just using onenote:// without specifying a destination, it's "by design" that you will receive an error.
We recommend you link to a specific page when opening OneNote from your application to avoid the error. The OneNote REST API returns a link to the page you've created when Creating a Page, and you can also retrieve a link using the "Copy Link to Page" function from within the iOS app.
As Nick pointed out, the OneNote app needs additional parameters to open successfully, without showing the "Cannot Open Link" alert. Here is what I did to solve the problem:
Note: In my app, the user is already logged in using the LiveSDK (Microsoft Account Login) so I have their Access Token saved.
I created an "Authorize OneNote" method that sends a request to the OneNote API to create a "Page" in the User's default notebook:
(void)AuthorizeOneNote
{
NSString *date = [NSString stringWithFormat:#"%#", [NSDate date]];
NSString *simpleHtml = [NSString stringWithFormat:
#"<html>"
"<head>"
"<title>\"%#\"</title>"
"<meta name=\"created\" content=\"%#\" />"
"</head>"
"<body>"
"<p></p>"
"</body>"
"</html>", #"Page Title", date];
NSData *presentation = [simpleHtml dataUsingEncoding:NSUTF8StringEncoding];
NSString *endpointToRequest = #"https://www.onenote.com/api/v1.0/pages";
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:endpointToRequest]];
request.HTTPMethod = #"POST";
request.HTTPBody = presentation;
[request addValue:#"text/html" forHTTPHeaderField:#"Content-Type"];
[request setValue:[#"Bearer " stringByAppendingString:#"LIVE-ID-ACCESS-TOKEN"] forHTTPHeaderField:#"Authorization"];
objConnectionOneNote = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
This is how I handle the response:
(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if (connection == objConnectionOneNote)
{
NSString *strData = [[NSString alloc]initWithData:objData encoding:NSUTF8StringEncoding];
NSMutableDictionary *dictData1 = [[NSMutableDictionary alloc] init];
dictData1 = [NSJSONSerialization JSONObjectWithData:objData options:kNilOptions error:nil];
oneNoteClientUrl = [dictData1 valueForKeyPath:#"links.oneNoteClientUrl.href"];
NSLog(#"Response: %#",oneNoteClientUrl);
NSLog(#"Response: %#",strData);
// Launch OneNote Client
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"onenote://"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:oneNoteClientUrl]];
}
else
{
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:#"https://itunes.apple.com/us/app/microsoft-onenote-for-iphone/id410395246?mt=8&uo=4"]];
}
}
There are couple things to note here:
This will create a new page every single time OneNote is launched from the app. In order to open the same page, you can persist the returned URL and use that to Open the client.
The Access Token from the MS Live Authentication expires in about an hour. When this happens, the OneNote API request returns a 401 Unauthorized response. To mitigate this, you can refresh the Access Token using the refresh token, which is also returned during Live Authentication.
Hope it helps!
With the addition of new automation app Workflow for iOS I'm extremely interested in figuring out how to incorporate OneNote into my actions.
I'm not looking to make an app and thus far I cannot find any examples for advanced url schemes for OneNote so the ability to grab a link that would open the OneNote app on either iPhone or iPad and have it go to the correct notebook and page would be great.
Ideally we could use a url scheme which OneNote:// works but need additional parameters for which notebook and page and how to create either a new notebook or page with that.
Workflow goes above and beyond what IFTTT can do (situation depending) and really looking forward to starting to use OneNote more due to automation possibilities.

How to clear username and password on CocoaLibSpotify logout?

I'm using the CocoaLibSpotify library to develop an iOS application that will utilize the Spotify API. I've got it just about where I want it, but I've run into a bit of a problem.
When the user touches my "Logout of Spotify" button, I execute the following code:
-(IBAction)logoutButtonTouched:(id)sender
{
// Clear out the user's settings that I am saving.
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
[[SPSession sharedSession] logout:^(void) {
SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]];
controller.allowsCancel = NO;
}];
}
This does indeed logout the user and display the SPLoginViewController, but my problem is, the username and password field still contain the values that they'd logged-in with. Does anyone know of a way to clear these fields when I display the SPLoginViewController?
This functionality isn't in the login controller, which is indeed a bug.
You can do it like this. Please note that this is really fragile code and will fail if any internal detail of the login controller changes, and it will in the future:
SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]];
id internalLoginViewController = [controller.viewControllers objectAtIndex:0];
UITextField *loginField = [internalLoginViewController valueForKey:#"usernameField"];
UITextField *passwordField = [internalLoginViewController valueForKey:#"passwordField"];
loginField.text = #"";
passwordField.text = #"";

Can't see Google Analytics data from my iOS app

I did follow the tutorial in Google developer website and put this code on my App delegate:
[GAI sharedInstance].trackUncaughtExceptions = YES;
[GAI sharedInstance].dispatchInterval = 20;
[GAI sharedInstance].debug = NO;
id<GAITracker> tracker = [[GAI sharedInstance] trackerWithTrackingId:#"My tracker code"];
[[GAI sharedInstance] trackerWithTrackingId:KGATrackerId];
Then in my viewcontrollers I placed this code in the viewDidLoad method:
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker trackView:#"Test View"];
When the GA debugger is on it actually states it's "hitting" the server with info; however in my Googla Analytics dashboard I can't see any new data in the newly created app section.
In my AppDelegate I have the following code in my didFinishLaunchingWithOptions
[[GANTracker sharedTracker] startTrackerWithAccountID:#"YOUR-ID-HERE"
dispatchPeriod:10
delegate:nil];
And to track events, like button clicks, I use this snippet in various places:
NSError *error;
if (![[GANTracker sharedTracker] trackPageview:#"/login/TouchedSubmit"
withError:&error]) {
// Handle error here
}
I have used this in multiple apps and I have never had any issues with my events not getting sent to Google-- Hope this helps

MGTwitterEngine Iphone oAuth

I hve try the MGTwitterEngine for oAuth from source https://github.com/kimptoc/MGTwitterEngine-1.0.8-OAuth
I am using this code for the MGTwitterEngine oAuth... but not working for me...
it give the same error I was getting in using xAuth without enabling xAuth Twitter integrated in Iphone App
Error Log is:
Twitter request failed! (3AFB8476-929F-4467-A4FE-DE43358CB62A) Error: The operation couldn’t be completed. (HTTP error 401.) ((null))
and one more thing I have not found anything in the for setting the application key and secret?
may be error due to this.. please help me.
Edited
Code on twitter button tab
-(IBAction)twitterBtnAct:(id)sender{
// Put your Twitter username and password here:
NSString *username = #"username";
NSString *password = #"password";
// Make sure you entered your login details before running this code... ;)
if ([username isEqualToString:#""] || [password isEqualToString:#""]) {
NSLog(#"You forgot to specify your username/password in AppController.m!");
}
// Create a TwitterEngine and set our login details.
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:username password:password];
// Get updates from people the authenticated user follows.
[twitterEngine getFollowedTimelineFor:username since:nil startingAtPage:0];
}
Amit Battan
HTTP 401 errors are about authentication problems. In the project, the application does:
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:username password:password]
Have you set this in your app?
I have use https://github.com/bengottlieb/Twitter-OAuth-iPhone for oAuth