-
Notifications
You must be signed in to change notification settings - Fork 145
Description
Hi, all
I have a view controller trying to login linkedin and post. But I couldn't get login, have the error message "Authorization failed Error Domain=WebKitErrorDomain Code=101 "(null). Really frustrated, hoping someone could help me! Thanks.
Here is my code
ViewController.h
import <UIKit/UIKit.h>
import "LIALinkedInApplication.h"
import "LIALinkedInHttpClient.h"
@interface ViewController : UIViewController
@Property (nonatomic, strong) LIALinkedInHttpClient *client;
- (IBAction) linkedInClicked:(id)sender;
- (void)requestMeWithToken:(NSString *)accessToken;
ViewController.m
import "ViewController.h"
@interface ViewController ()
@implementation ViewController
-
(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:@"http://www.google.com" clientId:@"" clientSecret:@"" state:@"something" grantedAccess:@[@"r_fullprofile", @"rw_nus", @"w_share"]];
self.client = [LIALinkedInHttpClient clientForApplication:application presentingViewController:nil];
}
- (IBAction) linkedInClicked:(id)sender { // Login into the account
[self.client getAuthorizationCode:^(NSString *code) {
[self.client getAccessToken:code success:^(NSDictionary *accessTokenData) {
NSString *accessToken = [accessTokenData objectForKey:@"access_token"];
[self requestMeWithToken:accessToken];
} failure:^(NSError *error) {
NSLog(@"Quering accessToken failed %@", error);
}];
} cancel:^{
NSLog(@"Authorization was cancelled by user");
} failure:^(NSError *error) {
NSLog(@"Authorization failed %@", error);
}];
} - (void)requestMeWithToken:(NSString *)accessToken {
[self.client GET:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~?oauth2_access_token=%@&format=json", accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result) {
NSLog(@"current user %@", result);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failed to fetch current user %@", error);
}];
}