title: IOSLinkedInAPI: Can't share post with the LinkedIn API
body: <p>I have been using following SDK to perform integration of LinkedIn into iOS and sharing post from iDevices.</p>
  <p>SDK is available here: <strong><a href="https://github.com/jeyben/IOSLinkedInAPI" rel="nofollow noreferrer">https://github.com/jeyben/IOSLinkedInAPI</a></strong></p>
  <p>In this code I can't find proper example code but however I had written some code through which post can be shared. Here is my code:</p>
  <p>In the code I have only single viewcontroller in which I have taken only two buttons, 1) Linked In Account [This button is used to present login controller and gets user successfully logged into the account] 2) Share [Allows user to share content on behalf of logged in user where the request fails]</p>
  <blockquote>
  <p>ViewController.h</p>
  </blockquote>
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &quot;LIALinkedInApplication.h&quot;
  #import &quot;LIALinkedInHttpClient.h&quot;
  
  @interface ViewController : UIViewController
  
  @property (nonatomic, strong) LIALinkedInHttpClient *client;
  
  - (IBAction) linkedInClicked:(id)sender;
  - (void)requestMeWithToken:(NSString *)accessToken;
  
  @end
  </code></pre>
  <blockquote>
  <p>ViewController.m</p>
  </blockquote>
  <pre><code>#import &quot;ViewController.h&quot;
  
  @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:@&quot;http://www.google.com&quot; clientId:@&quot;w57zqiw6cv73&quot; clientSecret:@&quot;Pj5MVxtkpbefau1v&quot; state:@&quot;something&quot; grantedAccess:@[@&quot;r_fullprofile&quot;, @&quot;r_network&quot;, @&quot;rw_nus&quot;]];
      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:@&quot;access_token&quot;];
              [self requestMeWithToken:accessToken];
          }                   failure:^(NSError *error) {
              NSLog(@&quot;Querying accessToken failed %@&quot;, error);
          }];
      }                      cancel:^{
          NSLog(@&quot;Authorization was cancelled by user&quot;);
      }                     failure:^(NSError *error) {
          NSLog(@&quot;Authorization failed %@&quot;, error);
      }];
  }
  
  - (IBAction) postMessage :(id)sender { // Post via logged in account, so, first go login and then share content
      NSString *strURL = @&quot;https://api.linkedin.com/v1/people/~/shares&quot;;
      
      NSMutableDictionary *contents=[[NSMutableDictionary alloc] init];
      [contents setValue:@&quot;description goes here&quot; forKey:@&quot;description&quot;];
      [contents setValue:@&quot;www.google.com&quot; forKey:@&quot;submitted-url&quot;];
      [contents setValue:@&quot;title goes here&quot; forKey:@&quot;title&quot;];
      
      NSMutableDictionary *visible=[[NSMutableDictionary alloc] init];
      [visible setValue:@&quot;anyone&quot; forKey:@&quot;code&quot;];
      
      NSMutableDictionary *updatedic=[[NSMutableDictionary alloc] init];
      
      [updatedic setObject:visible forKey:@&quot;visibility&quot;];
      [updatedic setObject:contents forKey:@&quot;content&quot;];
      [updatedic setValue:@&quot;Check out the LinkedIn Share API!&quot; forKey:@&quot;comment&quot;];
      //[updatedic setValue:@&quot;json&quot; forKey: @&quot;x-li-format&quot;];
      
      [self.client POST:strURL parameters:updatedic success:^(AFHTTPRequestOperation *operation, NSDictionary *dict) {
          NSLog(@&quot;Successfully posted&quot;, nil);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@&quot;Failed post&quot;, nil);
      }];
  }
  
  - (void)requestMeWithToken:(NSString *)accessToken {
      [self.client GET:[NSString stringWithFormat:@&quot;https://api.linkedin.com/v1/people/~?oauth2_access_token=%@&amp;format=json&quot;, accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result) {
          NSLog(@&quot;current user %@&quot;, result);
      }        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@&quot;failed to fetch current user %@&quot;, error);
      }];
  }
  </code></pre>
  <p>To make this app work, download content from the above SDK and add every required file into the project.</p>
  <p>When I try to login the app, I get successful message but after that when I try to share any post as described in above code, I get failure and see what is console:</p>
  <pre><code>Printing description of error:
  Error Domain=AFNetworkingErrorDomain Code=-1011 &quot;Request failed: unauthorized (401)&quot; UserInfo=0x8a6d500 {NSErrorFailingURLKey=https://api.linkedin.com/v1/people/~/shares, NSLocalizedDescription=Request failed: unauthorized (401), NSUnderlyingError=0x8ab1bd0 &quot;Request failed: unacceptable content-type: text/xml&quot;, AFNetworkingOperationFailingURLResponseErrorKey=&lt;NSHTTPURLResponse: 0x8a1f5f0&gt; { URL: https://api.linkedin.com/v1/people/~/shares } { status code: 401, headers {
      Connection = &quot;keep-alive&quot;;
      &quot;Content-Encoding&quot; = gzip;
      &quot;Content-Type&quot; = &quot;text/xml;charset=UTF-8&quot;;
      Date = &quot;Tue, 20 May 2014 09:38:01 GMT&quot;;
      Server = &quot;Apache-Coyote/1.1&quot;;
      &quot;Transfer-Encoding&quot; = Identity;
      Vary = &quot;*&quot;;
      &quot;Www-Authenticate&quot; = &quot;OAuth realm=\&quot;https://api.linkedin.com\&quot;&quot;;
      &quot;X-LI-UUID&quot; = &quot;wUQ+CTiK5WDItDrWLbZJFQ==&quot;;
      &quot;X-Li-Fabric&quot; = &quot;PROD-ELA4&quot;;
      &quot;X-Li-Pop&quot; = &quot;PROD-ELA4&quot;;
      &quot;x-li-format&quot; = xml;
      &quot;x-li-request-id&quot; = 30K08X3IL7;
  } }}
  </code></pre>
  <p>I have tried searching a lot on AFNetworking, LinkedIn authorization, Unauthorized access, etc. but could not found anything over this. Let me know if anyone of you are aware of something about this or suggest me any other option for LinkedIn iPhone SDK.</p>