jeyben / IOSLinkedInAPI

Simple and non intrusive library to get access tokens for LinkedIn using Oauth2.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authorization failed Error Domain=WebKitErrorDomain Code=101 "(null)

Allansk2 opened this issue · comments

commented

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;

@EnD

ViewController.m

import "ViewController.h"

@interface ViewController ()

@EnD

@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);
    }];
    }