I've created a starter project for using the LinkedIn Api via objective-c and the iPhone/iOS.
I'm sharing this because I don't know of anywhere else you can get these in one place:
- One project with OAuth, JSON, and LinkedIn Api examples integrated
- Fully functioning, add your app keys and run
- Uses JSON data, includes the fastest iOS parser available
- Does not use HTTP body, everything in Authentication header
- WebView integration, no figuring out how to mix in the UI pieces
- XCode 4.01 project
Hopefully this can save someone some time. OAuth has 1,000 tiny details that can go wrong - and usually do when you're first starting out.
Any feedback on the project or code is welcome.
Updated 4/11/2011: Rebuilt with XCode 4.01, added icons.
Download OAuthStarterKit_iOS_1_1
Hello,
Thanks for this amazing code, it saves my lots of time.
But i have one problem.
When i run your demo code then it retrieves AccessToken successfully and when i try on my code then it faild and return some body response with oauth_token, oauth_secret and oauth_varifier (Null)...so do you know that what is the problem.
And one more thing how can i retrieve oauth_token and oauth_secret from AccessToken's body response?
Thanks for your great help.
Posted by: Haresh | March 21, 2011 at 03:16 AM
Hi Haresh,
Is the testApi method working for you that displays your name and headline?
Or is it a separate api call that is not working?
To answer you last question where to get oauth_token and oauth_token_secret, those values are automatically extracted and placed into the "accessToken" variable.
After accessToken has been set by the code, you can see the properties are there in the console window by typing: "po accessToken". This will display the values you mention.
requestToken works the same way but you don't need requestToken for api calls, requestToken is needed only for the initial authorization.
Posted by: staff | March 21, 2011 at 05:45 AM
Thanks for your reply.
But i am facing strange problem. Your source code is working fine on simulator but its not loading on webview on device. I have checked your source code, it gives me same results, plz click on Get Linkedin Profile and it doesn't display anything on device but it works fine on simulator.
Can you plz guide me if you have solved that problem?
Thanks so much.
Posted by: Haresh | April 05, 2011 at 06:35 AM
hello,
i got the problem, it showing me We were unable to find the authorization token, error in device.
Can u plz tell me that how to fix it?
Regards,
Haresh.
Posted by: Haresh | April 07, 2011 at 05:15 AM
Haresh,
I've updated the project, please give it another try. This version I tested on the iPhone 4, and iPad 1, both are working fine.
Lee
Posted by: staff | April 11, 2011 at 03:06 PM
Hello Lee, i found very useful your code, but i0m trying to implements an oauth 1.0a with uso of a pin after the user login.
Have you an idea on how to di this starting from your project?
Thanks in advice!
Tuma
Posted by: Tuma | April 26, 2011 at 01:36 PM
Hi Tuma,
Are you sure you want to insist that the user enter a PIN as part of the login?
Entering a PIN is an "Out of Band" (OOB) approach to OAuth and more work for the user compared to entering their username and password.
Posted by: Lee Whitney | April 26, 2011 at 08:18 PM
Hello,
Congratulation for your job !!!
I try for several hours to use the Invite API with id (not email).
I try to use you library.
1. Your sample code is working on my iPhone
2. I try to replace your testCallApi with the following code to use the InviteById feature:
This API needs to use a POST Method with XML inside.
Using my code, i have a 401 UnAuthenticated Error...
Do you have sample code to send this kind of "POST" request with your API ?
Thank you for your help.
- (void)testApiCall
{
NSString * requestString= @"\
\
\
\
\
\
\
Invitation to Connect\
Please join my professional network on LinkedIn.\
\
\
friend\
\
NAME_SEARCH\
y6Xn\
\
\
\
";
NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/mailbox"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:consumer
token:self.accessToken
callback:nil
signatureProvider:nil];
[request setHTTPMethod:@"POST"];
[request prepare];
[request setHTTPBody:[requestString dataUsingEncoding:NSUTF8StringEncoding]];
//[request setValue:@"json" forHTTPHeaderField:@"x-li-format"]; //not used, want to send XML
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:@selector(testApiCallResult:didFinish:)
didFailSelector:@selector(testApiCallResult:didFail:)];
[request release];
}
Posted by: Fvisticot | May 08, 2011 at 02:16 AM
Hi Fred,
Kirsten at LinkedIn has updated the project to include an add update sample post.
This should give you an idea of how to do write operations. You can get the updated version here:
https://github.com/synedra/LinkedIn-OAuth-Sample-Client
Please check it out and either of us would be glad to answer more questions.
Regards
Posted by: Lee | May 17, 2011 at 10:57 AM
Hey thanks for the contribution to the community.
I'm interested in creating more or less the equivalent for the Mac desktop [ yeah they still do exist :-) ]
Most desktop application developers have yet to move to XC4 because of legacy issues.
So I'll be back this down to XC3 for more universal appeal.
Is there any functionality that REQUIRES XC4?
Is there any gotchas here that I should be aware of moving this to Cocoa?
Posted by: Steve | May 21, 2011 at 05:52 PM
Hi Steve,
I only say XCode 4.01 is required because that is what I used and what I can guarantee will work.
However I haven't intentionally precluded XCode 3.x from working. So it might just work no problem.
If you find anything that needs to be fixed I would be glad to help out.
thanks-
Posted by: Lee | May 30, 2011 at 08:20 AM
Hi Lee,
Great work!! I am pretty new to iOS dev and OAuth. Could you please let me know how could I share update on Linkedin. I tried looking up but I could not find any good tutorials.
Thanks,
Dexter
Posted by: Dexter | July 21, 2011 at 10:57 AM
Just a quick heads up for any newbies out there like myself. I grabbed the latest version of the code from git hub and I couldn't get it to accept my api key for the life of me. Here's the fix... I dunno if this is something new that linked in is doing, but my key and secret were less than 64 characters in length.
So just change the viewdidappear code to lower the length values and your money. I lowered mine to 1 and now I'm rockin and rolling.
- (void)viewDidAppear:(BOOL)animated
{
if ([apikey length] < 1 || [secretkey length] < 1)
Thanks again for putting this together!
Posted by: Dallas West | July 30, 2011 at 02:17 PM
Hi,
Thanks for sharing your source code.
I'm trying to test it, but something is wrong in my api key and secret.
I checked it a thousand times and it's correct, but when I log it, the api key length is 12 and the secret length is 16, when it should be 64, right?
Any idea what's going on?
Posted by: Marcela Kashiwagi Silveira | August 06, 2011 at 07:34 AM
hi,
I use this code for invitation using the email but every time I got the error of UNAuthororized message...
any one know how can solve this....
Thanks in advance.
Posted by: omkarnath shashtri | August 16, 2011 at 07:35 AM
Hello,
I'm also facing the same problem....
I receive the response every time same.
401
1313505575052
CS5OHFZ6UE
0
Unknown authentication scheme
Posted by: david | August 16, 2011 at 07:41 AM
I want to enter my login and password every time when i touch "Get LinkedIn Profile" button?? Anybody help me?
Posted by: Scholl1991 | October 27, 2011 at 07:58 AM
i get the secret key and api key from linked in website and put them in the right place in code then i run the demo when i try to put Name & headline it give me exception in Main function EXC_BAD_ACC
and when i try to click on the button without fill the textfeilds it tell me to put your API key and secret key
how can i solve this problem
Posted by: khaled | November 01, 2011 at 05:16 AM
How to logout using linkedin api ?
Posted by: Test | November 15, 2011 at 09:01 PM
hi,
i downloaded this iphone proj. I added API key and SECRET key alos. when i run the app and click on "Get Linkedin profile" it's always telling me "You must add apikey and secret key .see the project file Readme.txt ".
Posted by: shilpa | November 16, 2011 at 05:02 AM