使用Objective C在LinkedIn上共享内容

时间:2017-06-11 19:32:38

标签: objective-c sharing linkedin-api http-status-code-400

我整合了最新的sdks个Linkedin来分享内容。因为它以前工作但现在它给出了错误。请找到以下错误消息。

  

错误域= LISDKErrorAPIDomain代码= 400“(null)”   的UserInfo = {LISDKAuthErrorAPIResponse =}

请在共享内容的应用程序中找到我正在使用的以下代码。

- (IBAction)postOnLinkedin:(id)sender {

    if ([LISDKSessionManager hasValidSession]) {

        [self postOnLinedln];
    }

    else {

      [LISDKSessionManager createSessionWithAuth:[NSArray 
      arrayWithObjects:LISDK_BASIC_PROFILE_PERMISSION, 
      LISDK_EMAILADDRESS_PERMISSION, LISDK_W_SHARE_PERMISSION, nil]
         state:@"some state" showGoToAppStoreDialog:YES

          successBlock:^(NSString *returnState) {

              [self postOnLinedln];
          }

          errorBlock:^(NSError *error) {

            [self showAlert:error.localizedDescription];
          }
      ];
   }
 }

- (void)postOnLinedln {

    NSString *url = @"https://api.linkedin.com/v1/people/~/shares";

    NSString *payload = [NSString stringWithFormat:@"{\"comment\":\"Hello\","
                         "\"content\":{ \"title\":\"Title\","
                         "\"description\":\"%@\","
                         "\"submitted-url\":\"\","
                         "\"submitted-image-url\":\"\"},"
                         "\"visibility\":{ \"code\":\"anyone\"}}", self.description];

    if ([LISDKSessionManager hasValidSession]) {

        [[LISDKAPIHelper sharedInstance] postRequest:url stringBody:payload
                                             success:^(LISDKAPIResponse *response) {

           // do something with response                                                     
          dispatch_sync(dispatch_get_main_queue(),^{

             [self showAlert:@"Posted successfully"];                                                         
          });
      }

      error:^(LISDKAPIError *apiError) {

           // do something with error                                                       
           dispatch_sync(dispatch_get_main_queue(),^{

               [self showAlert:apiError.description];
           });
       }];
     }

    else {

        [self showAlert:@"No Valid session Linkdln"];
    }
}

由于我已经通过LinkedIn的开发人员门户解决了这个问题,但没有得到任何帮助。

3 个答案:

答案 0 :(得分:0)

回复告诉您未进行身份验证。

LinkedIN OAuth API

因此,您的问题在于需要首先进行身份验证调用。

答案 1 :(得分:0)

实际上,你没有传递linkedin guideline中提到的描述字段中超过256的字符。

有关详细信息,请参阅以下屏幕截图:

screenshot

答案 2 :(得分:0)

删除你的有效负载并添加它。

NSString *url = @"https://api.linkedin.com/v1/people/~/shares";
    NSString *payload = [NSString stringWithFormat:@"{\"comment\":\"Hello\","
                         "\"content\":{ \"title\":\"Title\","
                         "\"description\":\"hi\","
                         "\"submitted-url\":\"hello\","
                         "\"submitted-image-url\":\"\"},"
                         "\"visibility\":{ \"code\":\"anyone\"}}"];