<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2331596561060948127</id><updated>2011-07-07T20:30:51.468-07:00</updated><category term='objective-c'/><category term='iPhone'/><category term='OAuth'/><category term='Fellowship Technologies'/><title type='text'>Chad Meyer</title><subtitle type='html'>I created this blog to try and demonstrate some of the situations I have been in and get peep's feedback in programming and other funness.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://chadillac-meyer.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2331596561060948127/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://chadillac-meyer.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Chad</name><uri>http://www.blogger.com/profile/15492902313627025935</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2331596561060948127.post-2210667737371426661</id><published>2009-05-22T17:24:00.001-07:00</published><updated>2009-05-25T19:57:01.136-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='OAuth'/><category scheme='http://www.blogger.com/atom/ns#' term='iPhone'/><category scheme='http://www.blogger.com/atom/ns#' term='objective-c'/><category scheme='http://www.blogger.com/atom/ns#' term='Fellowship Technologies'/><title type='text'>Consume F1 API for iPhone</title><content type='html'>The Dynamic Church Conference (DC09) Dev track was a great success. Developers and interested users were able to get a first hand look at the powerful ways they might include the Fellowship One API in their development to build some really cool things, not to mention the premier of our NOM NOM NOM shirts!&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Before the conference, Matt Vasquez and I were asked to build an iPhone application to consume the API. Besides the fact that we had to scramble to get an understanding of what objective-c and Cocoa (silent a) was, we also had to find an OAuth library that would fit our needs. We went with &lt;a href="http://code.google.com/p/oauthconsumer/" target="_blank"&gt;OAConsumer&lt;/a&gt;.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;We made slight modifications to the OAConsumer library to help fit our needs. We changed the NSMutableURLRequest+Parameters.m file to comment out the way they handle the Content-Type and the HTTPBody. We wanted to handle that ourselves.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div  style="background-color:#000;"&gt;&lt;br /&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;        &lt;/span&gt;// POST, PUTencodedParameterPairs        &lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;// NSData *postData = [encodedParameterPairs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;        &lt;/span&gt;// [self setHTTPBody:postData];&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#00a0ff;"&gt;&lt;span style="color:#ffffff;"&gt;        [&lt;/span&gt;&lt;span style="color:#d31895;"&gt;self&lt;/span&gt;&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;setValue&lt;span style="color:#ffffff;"&gt;:[&lt;/span&gt;NSString&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;stringWithFormat&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff2c38;"&gt;@"%d"&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;, [[&lt;/span&gt;&lt;span style="color:#d31895;"&gt;self&lt;/span&gt;&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;HTTPBody&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;length&lt;span style="color:#ffffff;"&gt;]] &lt;/span&gt;forHTTPHeaderField&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff2c38;"&gt;@"Content-Length"&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;        &lt;/span&gt;// [self setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;We did this because we wanted to have control of the HTTPBody, and by having the Content-Type as www-form-urlencoded, it forces everything in the HTTPBody to become part of the raw request.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;We will look at the way we do authentication. Our downloaded library will also show ways to call any URL.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;First things first, we need to initialize a OAConsumer object. For those of you that don't understand the concepts of OAuth, each application that wants to talk to the F1 API will be given a consumer key and consumer secret. When the initialization of the OAConsumer happens, you will notice that we pass over the key and secret as parameters. We store the consumer key and consumer secret in a property list called "FTAPI.plist" and we created our own Utility library for pulling the correct values from the plist.&lt;/div&gt;&lt;br /&gt;&lt;div style="background-color:#000000"&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;// Create an OAConsumer object&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span style="color:#23ff83;"&gt;OAConsumer&lt;/span&gt; *oaConsumer = [[&lt;span style="color:#23ff83;"&gt;OAConsumer&lt;/span&gt; &lt;span style="color:#00a0ff;"&gt;alloc&lt;/span&gt;] &lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;initWithKey&lt;span style="color:#ffffff;"&gt;:[&lt;/span&gt;&lt;span style="color:#d31895;"&gt;self&lt;/span&gt;&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;consumerKey&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span class="Apple-tab- span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;secret&lt;span style="color:#ffffff;"&gt;:[&lt;/span&gt;&lt;span style="color:#d31895;"&gt;self&lt;/span&gt;&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;consumerSecret&lt;span style="color:#ffffff;"&gt;]];&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Next we will create a OAMutableURLRequest object. This is the request object that will be used to fetch the data (call the API). You initialize the URL request with the url that needs to be accessed, the OAConsumer object that we created above and a nil OAToken because since this request is being executed to generated an access token, we don't have an OAToken yet.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We then set the HTTPMethod to be a POST and set the HTTPBody to be the 64 bit encoded credentials that were provided. The consumer key that Fellowship Tech uses for the iPhone application is marked as trusted and public, which turns the application into a first party application, allowing us to request an access token via credentials and bypassing the request token mechanism. The final change we make to the request is to the Content Type, we set it to be application/xml.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The final section of the code below is the initialization of the OAAsynchronousDataFetcher object. We initialize the object with the newly constructed URL Request, along with a delegate and 2 selectors. These selectors are methods that will get called once the data fetcher is done. This allows for the main thread to continue processing while the request is being made. An example would be when we wanted to hide the keyboard and show a loading UIView. For more information on URL Requests, please look at the &lt;a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html" target="_blank"&gt;NSURLConnection class reference&lt;/a&gt;.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div  style="background-color:#000000;"&gt;&lt;br /&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;OAMutableURLRequest&lt;span style="color:#ffffff;"&gt; *request = [[&lt;/span&gt;OAMutableURLRequest&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;alloc&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;initWithURL&lt;span style="color:#ffffff;"&gt;:accessTokenURL&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#23ff83;"&gt;consumer&lt;/span&gt;:oaConsumer&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;                                 &lt;span style="color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;token&lt;/span&gt;:&lt;span style="color:#d31895;"&gt;nil&lt;/span&gt;   &lt;span style="color:#41cc45;"&gt;// we don't have a Token yet&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;                                 &lt;span style="color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;realm&lt;/span&gt;:&lt;span style="color:#d31895;"&gt;nil&lt;/span&gt;   &lt;span style="color:#41cc45;"&gt;// our service provider doesn't specify a realm&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;                                 &lt;span style="color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;signatureProvider&lt;/span&gt;:&lt;span style="color:#d31895;"&gt;nil&lt;/span&gt;]; &lt;span style="color:#41cc45;"&gt;// use the default method, HMAC-SHA1&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-style-span"  style="color:#41CC45;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span class="Apple-style-span"  style="color:#33CC00;"&gt;// Set the request to a POST for access token&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;[request &lt;span style="color:#00a0ff;"&gt;setHTTPMethod&lt;/span&gt;:&lt;span style="color:#ff2c38;"&gt;@"POST"&lt;/span&gt;];&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;// Set the body to be the encoded username and password&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;[request &lt;span style="color:#00a0ff;"&gt;setHTTPBody&lt;/span&gt;: [[&lt;span style="color:#00a0ff;"&gt;NSData&lt;/span&gt; &lt;span style="color:#00a0ff;"&gt;alloc&lt;/span&gt;]&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;initWithData&lt;/span&gt;:[encodedUserCreds&lt;span class="Apple-style-span" style="color: rgb(0, 160, 255); "&gt;dataUsingEncoding&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;NSASCIIStringEncoding&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;&lt;span style="color:#ffffff;"&gt;&lt;/span&gt;allowLossyConversion&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;&lt;span style="color:#d31895;"&gt;YES&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;]]];&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ff2c38;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ff2c38;"&gt;&lt;span style="color:#ffffff;"&gt;[request &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;setValue&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;@"application/xml"&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;forHTTPHeaderField&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;@"Content-Type"&lt;span style="color:#ffffff;"&gt;]; &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;// Fetch the data associated with the request&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;OAAsynchronousDataFetcher&lt;span style="color:#ffffff;"&gt; *fetcher = [[&lt;/span&gt;OAAsynchronousDataFetcher&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;alloc&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;   &lt;/span&gt;initWithRequest&lt;span style="color:#ffffff;"&gt;:request &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span style="color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;delegate&lt;/span&gt;:&lt;span style="color:#d31895;"&gt;self&lt;/span&gt; &lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span style="color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;didFinishSelector&lt;/span&gt;:&lt;span style="color:#d31895;"&gt;@selector&lt;/span&gt;(accessTokenSucceed: withData:) &lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span style="color:#23ff83;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;didFailSelector&lt;/span&gt;:&lt;span style="color:#d31895;"&gt;@selector&lt;/span&gt;(accessTokenFail: withData:)];&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;// Start the fetch&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;[fetcher &lt;span style="color:#00a0ff;"&gt;start&lt;/span&gt;];&lt;/p&gt;&lt;/div&gt;&lt;/code&gt;&lt;/div&gt;&lt;br /&gt;The final code snippet we will look at is the selector methods for after the request is complete. Please notice that the OAAsynchronousDataFetcher object we created requires a didFinishSelector parameter. This is a @selector that will be called after the fetcher is complete. We built a custom class called FTOAuthResult to store and return OAuth responses. The data fetcher from the above code will return an OAServiceTicket along with the data. &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The first thing the succeed method does is create an FTOAuthResult object which will be used as the return object when we call the parent delegate selector. If the request is successful we convert the NSData "data" object to an NSString so we can later turn it into an OAToken object. The other thing we do is get the response headers from the OAServiceTicket response property (ticket.response). We do this because we want to get the content-location, this is the URL to the person detail information that was authenticated.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Next we will create an OAToken object from the response body which is the string representation of the NSData "data" object that was mentioned earlier. We did this so we could easily get the access token and secret so we could throw them into the NSUserDefaults, yes we created our own class for this called FTUserDefaults. We did this to easily get and set User Defaults. I won't go into that here, but it is available in the downloaded code.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The last thing we do in this method is call the parent delegates success selector. That means the controller that called the method [FTOAuth authenticateUser:] also provided a selector to go to when the request was complete.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div  style="background-color:#000;"&gt;&lt;br /&gt;&lt;div&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;- (&lt;span style="color:#d31895;"&gt;void&lt;/span&gt;) accessTokenSucceed: (&lt;span style="color:#23ff83;"&gt;OAServiceTicket&lt;/span&gt; *)ticket withData:(&lt;span style="color:#00a0ff;"&gt;NSData&lt;/span&gt; *)data {&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#33CC00;"&gt;// Build a an FTOauthResult for the current object&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;FTOAuthResult&lt;span style="color:#ffffff;"&gt; *oauthResult = [[&lt;/span&gt;FTOAuthResult&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;alloc&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;init&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#33CC00;"&gt;// Set the FTOauth succeed to the ticket succeed&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;oauthResult.&lt;span style="color:#23ff83;"&gt;isSucceed&lt;/span&gt; = ticket.&lt;span style="color:#23ff83;"&gt;didSucceed&lt;/span&gt;;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#33CC00;"&gt;// If the authenticate was a success then find the My Info URL, &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#33CC00;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#33CC00;"&gt;// store it and store the access token and secret&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;span style="color:#d31895;"&gt;if&lt;/span&gt; (ticket.&lt;span style="color:#23ff83;"&gt;didSucceed&lt;/span&gt;) {&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#00a0ff;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;NSString&lt;span style="color:#ffffff;"&gt; *responseBody = [[&lt;/span&gt;NSString&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;alloc&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;initWithData&lt;span style="color:#ffffff;"&gt;:data&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#00a0ff;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;     &lt;/span&gt;&lt;/span&gt;encoding&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;NSUTF8StringEncoding&lt;span style="color:#ffffff;"&gt;];&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;// Get the HTTPHeaders to find the Persons URL for "My Info"&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;NSDictionary&lt;/span&gt; *responseHeaderDictionary = [[&lt;span style="color:#00a0ff;"&gt;NSDictionary&lt;/span&gt; &lt;span style="color:#00a0ff;"&gt;alloc&lt;/span&gt;] &lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#00a0ff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;initWithDictionary&lt;span style="color:#ffffff;"&gt;:[(&lt;/span&gt;NSHTTPURLResponse&lt;span style="color:#ffffff;"&gt; *)ticket.&lt;/span&gt;&lt;span style="color:#23ff83;"&gt;response&lt;span class="Apple-tab-span" style="white-space:pre"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;&lt;/span&gt;allHeaderFields&lt;span style="color:#ffffff;"&gt;]];&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt; &lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;span style="color:#23ff83;"&gt;OAToken&lt;/span&gt; *accessTokenResponse = [[&lt;span style="color:#23ff83;"&gt;OAToken&lt;/span&gt; &lt;span style="color:#00a0ff;"&gt;alloc&lt;/span&gt;]&lt;span class="Apple-tab-span" style="white-space:pre"&gt;      &lt;/span&gt;&lt;span style="color:#23ff83;"&gt;initWithHTTPResponseBody&lt;/span&gt;:responseBody];&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#41cc45;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;// &lt;span class="Apple-style-span"  style="color:#33CC00;"&gt;Assign&lt;/span&gt; the OAToken values to the NSUserDefaults&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[[&lt;/span&gt;FTUserDefaults&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;sharedInstance&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;setAccessToken&lt;span style="color:#ffffff;"&gt;: [accessTokenResponse &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;key&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;]];&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[[&lt;/span&gt;FTUserDefaults&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;sharedInstance&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;setAccessTokenSecret&lt;span style="color:#ffffff;"&gt;:[accessTokenResponse &lt;/span&gt;secret&lt;span style="color:#ffffff;"&gt;]];&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[[&lt;/span&gt;FTUserDefaults&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;sharedInstance&lt;span style="color:#ffffff;"&gt;] &lt;/span&gt;setMyInfoURL&lt;span style="color:#ffffff;"&gt;:[responseHeaderDictionary&lt;span class="Apple-tab-span" style="white-space:pre"&gt;     &lt;/span&gt;&lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;valueForKey&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;&lt;span style="color:#ff2c38;"&gt;@"Content-Location"&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;]];&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0pxcolor:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;oauthResult.&lt;span style="color:#23ff83;"&gt;returnData&lt;/span&gt; = responseHeaderDictionary;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/p&gt; &lt;p color="#ffffff" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier;  min-height: 13.0px"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p color="#41cc45" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; "&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#33CC00;"&gt;// Call the delegate selector&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#23ff83;"&gt;&lt;span style="color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;[&lt;/span&gt;parentDelegate&lt;span style="color:#ffffff;"&gt; &lt;/span&gt;&lt;span style="color:#00a0ff;"&gt;performSelector&lt;/span&gt;&lt;span style="color:#ffffff;"&gt;:&lt;/span&gt;didFinishSelector&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color:#ffffff;"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;      &lt;/span&gt; &lt;span style="color:#00a0ff;"&gt;withObject&lt;/span&gt;:oauthResult];&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color: #ffffff"&gt;}&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Courier; color: #ffffff"&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;This hopefully shows an easy way to consume the Fellowship One API for authentication. Below are two links that will have more detailed code on how to call other API urls.&lt;br /&gt;&lt;br /&gt;Fellowship OAuth Zip File: &lt;a href="https://experience.fellowshipone.com/Developers/artifacts/FTOAuth.zip"&gt;FTOAuth.zip&lt;/a&gt;&lt;br /&gt;Fellowship iPhone DC09 Presentation: &lt;a href="https://experience.fellowshipone.com/Developers/artifacts/DC09_iPhone_PDF.pdf" target="_blank"&gt;iPhone Presentation&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2331596561060948127-2210667737371426661?l=chadillac-meyer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://chadillac-meyer.blogspot.com/feeds/2210667737371426661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://chadillac-meyer.blogspot.com/2009/05/consume-f1-api-for-iphone.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2331596561060948127/posts/default/2210667737371426661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2331596561060948127/posts/default/2210667737371426661'/><link rel='alternate' type='text/html' href='http://chadillac-meyer.blogspot.com/2009/05/consume-f1-api-for-iphone.html' title='Consume F1 API for iPhone'/><author><name>Chad</name><uri>http://www.blogger.com/profile/15492902313627025935</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry></feed>
