If Josh Ran The World http://ifjoshrantheworld.com It would be nice posterous.com Sun, 15 Apr 2012 12:34:00 -0700 Instagram OAuth Login for iOS (Objective-C) http://ifjoshrantheworld.com/instagram-oauth-login-for-ios-objective-c http://ifjoshrantheworld.com/instagram-oauth-login-for-ios-objective-c

After posting some questions online about setting up an OAuth connection for Instagram on an iOS App a few people asked me for help with how I implamented the integration.  Here is a snipit of my code to hopefully help you all out.

static NSString *const authUrlString = @" https://api.instagram.com/oauth/authorize/ ";
static NSString *const tokenUrlString = @" https://api.instagram.com/oauth/access_token/ ";

// ADD YOUR CLIENT ID AND SECRET HERE
static NSString *const clientID = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
static NSString *const clientSecret = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

// YOU NEED A BAD URL HERE - THIS NEEDS TO MATCH YOUR URL SET UP FOR YOUR
// INSTAGRAM APP
static NSString *const redirectUri = @" http://mydomain.com/NeverGonnaFindMe/ ";

// CHANGE TO THE SCOPE YOU NEED ACCESS TO
static NSString *const scope = @"comments+relationships+likes";

@implementation OAuthLoginController

@synthesize webView = _webView;
@synthesize activityIndicator = _activityIndicator;

// GRAB THE URL TRAFFIC TO CATCH THE ACCESS TOKEN OUT OF THE RETURN URL
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *Url = [request URL];
    NSArray *UrlParts = [Url pathComponents];
    if ([[UrlParts objectAtIndex:(1)] isEqualToString:@"NeverGonnaFindMe"]) {
        // CONVERT TO STRING AN CLEAN
        NSString *urlResources = [Url resourceSpecifier];
urlResources = [urlResources stringByReplacingOccurrencesOfString:@"?" withString:@""];
        urlResources = [urlResources stringByReplacingOccurrencesOfString:@"#" withString:@""];

        // SEPORATE OUT THE URL ON THE /
        NSArray *urlResourcesArray = [urlResources componentsSeparatedByString:@"/"];
        // THE LAST OBJECT IN THE ARRAY
        NSString *urlParamaters = [urlResourcesArray objectAtIndex:([urlResourcesArray count]-1)];
        // SEPORATE OUT THE URL ON THE &
        NSArray *urlParamatersArray = [urlParamaters componentsSeparatedByString:@"&"];

                 if([urlParamatersArray count] == 1) {
            NSString *keyValue = [urlParamatersArray objectAtIndex:(0)];
            NSArray *keyValueArray = [keyValue componentsSeparatedByString:@"="];

            if([[keyValueArray objectAtIndex:(0)] isEqualToString:@"access_token"]) {
                // THE TOKEN IS NOW IN [keyValueArray objectAtIndex:(1)]

                                 // YAY WE HAVE AN ACCESS TOKEN TO SAVE IN THE KEYCHAIN OR USER DEFAULTS

                                 // SWITCH STORYBOARDS INTO THE MAIN APP
                UIStoryboard *settingsStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
                UIViewController *initialSettingsVC = [settingsStoryboard instantiateInitialViewController];
                initialSettingsVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
                [self presentModalViewController:initialSettingsVC animated:YES];
            }
        } else {
            // THERE WAS AN ERROR
        }

                 [self dismissModalViewControllerAnimated:YES];
        return NO;
    }
    return YES;
}

// ACTIVITY INDICATOR
- (void)webViewDidStartLoad:(UIWebView *)webView{
    [_activityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [_activityIndicator stopAnimating];
}

// INITIATE THE VIEW WITH THE CORRECT URL
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSString *fullAuthUrlString = [[NSString alloc]
                                   initWithFormat:@"%@/?client_id=%@&redirect_uri=%@&scope=%@&response_type=token&display=touch",
                                   authUrlString,
                                   clientID,
                                   redirectUri,
                                   scope
                                ];
    NSURL *authUrl = [NSURL URLWithString:fullAuthUrlString];
    NSURLRequest *myRequest = [[NSURLRequest alloc] initWithURL:authUrl];
    [_webView loadRequest:myRequest];
}

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Fri, 23 Mar 2012 12:53:00 -0700 #Yellow #cake with #chocolate #gnash. http://ifjoshrantheworld.com/yellow-cake-with-chocolate-gnash http://ifjoshrantheworld.com/yellow-cake-with-chocolate-gnash

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Tue, 20 Mar 2012 18:31:21 -0700 Yes that is a #screw. What else would hold in the #crown. http://ifjoshrantheworld.com/yes-that-is-a-screw-what-else-would-hold-in-t http://ifjoshrantheworld.com/yes-that-is-a-screw-what-else-would-hold-in-t
Taken at Upper Dublin Dentistry

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Tue, 20 Mar 2012 14:55:51 -0700 #Weather was so nice today. Took this one of the #Audi by some #spring #blooms. http://ifjoshrantheworld.com/weather-was-so-nice-today-took-this-one-of-th http://ifjoshrantheworld.com/weather-was-so-nice-today-took-this-one-of-th
Taken at Bed Bath & Beyond

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Mon, 19 Dec 2011 16:10:03 -0800 One year ago today I posted my first picture on the #iPhone only app that few people knew about. So much has changed and I glad to be part of the extended #instagram family. #InstaVersery #anniversary http://ifjoshrantheworld.com/one-year-ago-today-i-posted-my-first-picture http://ifjoshrantheworld.com/one-year-ago-today-i-posted-my-first-picture

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Thu, 08 Dec 2011 19:00:56 -0800 #twitter adds keyboard shortcuts to the web interface. http://ifjoshrantheworld.com/twitter-adds-keyboard-shortcuts-to-the-web-in http://ifjoshrantheworld.com/twitter-adds-keyboard-shortcuts-to-the-web-in

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 18 Sep 2011 21:47:00 -0700 OS X 10.8 Buttons Pure CSS3 http://ifjoshrantheworld.com/os-x-108-buttons-pure-css3 http://ifjoshrantheworld.com/os-x-108-buttons-pure-css3

After seeing a few of the form and navigation elements from OS X 10.8 I decided to incorporate and recreate them in CSS.  Below is the styling for buttons. I also want to build a search input box which will be next.

.button{
    background:#ddd;
    background:-webkit-gradient(linear, left top, left bottom, from(#ddd), to(#c2c2c2));
    background-image:-moz-linear-gradient(top, #ddd, #c2c2c2);
    border:1px solid #838383;
    border-radius:15px;
    color:#fff;
    display:block;
    padding:10px 20px;
    text-align:center;
    text-decoration:none;
    text-shadow:#555 0px 2px 2px;
}
.button:hover{
    background:#81acd4;
    background:-webkit-gradient(linear, left top, left bottom, from(#81acd4), to(#527ea5));
    background-image:-moz-linear-gradient(top, #81acd4, #527ea5);
    border:1px solid #005ab1;
}
.button:active{
    background:#527ea5;
    background:-webkit-gradient(linear, left top, left bottom, from(#527ea5), to(#81acd4));
    background-image:-moz-linear-gradient(top, #527ea5, #81acd4);
    border:1px solid #005ab1;
}

To see this live in action check out the latest version of gramsby.me with our newly designed home page and site.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 24 Jul 2011 16:36:24 -0700 After the #rain. http://ifjoshrantheworld.com/after-the-rain http://ifjoshrantheworld.com/after-the-rain

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Fri, 08 Jul 2011 12:49:26 -0700 Rain rain http://ifjoshrantheworld.com/rain-rain http://ifjoshrantheworld.com/rain-rain

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 26 Jun 2011 21:02:15 -0700 Salad, Chicken, Wild Rice and Snap Peas http://ifjoshrantheworld.com/salad-chicken-wild-rice-and-snap-peas http://ifjoshrantheworld.com/salad-chicken-wild-rice-and-snap-peas

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Thu, 16 Jun 2011 11:51:44 -0700 Untitled http://ifjoshrantheworld.com/57434256 http://ifjoshrantheworld.com/57434256

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Thu, 02 Jun 2011 16:08:23 -0700 A salad waiting to happen http://ifjoshrantheworld.com/a-salad-waiting-to-happen http://ifjoshrantheworld.com/a-salad-waiting-to-happen

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 15 May 2011 17:14:50 -0700 Raining in my condo http://ifjoshrantheworld.com/raining-in-my-condo http://ifjoshrantheworld.com/raining-in-my-condo

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 15 May 2011 15:35:05 -0700 Yummm http://ifjoshrantheworld.com/yummm http://ifjoshrantheworld.com/yummm

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 15 May 2011 15:31:39 -0700 Mango salsa is the key http://ifjoshrantheworld.com/mango-salsa-is-the-key http://ifjoshrantheworld.com/mango-salsa-is-the-key

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Thu, 12 May 2011 10:54:49 -0700 Tablet to Web OS Notebook to ... http://ifjoshrantheworld.com/tablet-to-web-os-notebook-to http://ifjoshrantheworld.com/tablet-to-web-os-notebook-to

Google Announced a Chrome OS Webbook, Apple has the iPad… What could be next?

 

I love the idea of both these devices and would love to see a mashup, a web OS like chrome on a table, a WebPad or WebTab.  Google or its partners are trying to play catch up to Apple in the tablet space why not just skip over getting a smart phone OS on a tablet and jump to the next stage which would be the Web OS tablet.

 

The Web OS tablet will be the next wonder device.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Mon, 09 May 2011 15:12:08 -0700 Mini-Rocks. Pony size. http://ifjoshrantheworld.com/mini-rocks-pony-size http://ifjoshrantheworld.com/mini-rocks-pony-size

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 08 May 2011 08:36:58 -0700 Beautiful day in the park http://ifjoshrantheworld.com/beautiful-day-in-the-park http://ifjoshrantheworld.com/beautiful-day-in-the-park
Taken at Penny Pack Park

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Sun, 01 May 2011 14:16:51 -0700 Got some new kicks today. First pair of non New Balances in 3 years. http://ifjoshrantheworld.com/got-some-new-kicks-today-first-pair-of-non-ne http://ifjoshrantheworld.com/got-some-new-kicks-today-first-pair-of-non-ne

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine
Tue, 01 Mar 2011 06:19:57 -0800 Breakfast of developers http://ifjoshrantheworld.com/breakfast-of-developers http://ifjoshrantheworld.com/breakfast-of-developers
Taken at Huntingdon Valley, PA

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1757641/c19bc02e16034bf29b1a74c2711b5736_7.jpg http://posterous.com/users/4al3MzWMk5ln Joshua Oiknine joshoiknine Joshua Oiknine