使用 Objective C 在 LinkedIn 上分享内容
Sharing the content on LinkedIn using Objective C
我集成了最新的sdksLinkedin分享内容。因为它以前是有效的,但现在它给出了错误。请找到以下错误消息。
Error Domain=LISDKErrorAPIDomain Code=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 的开发者门户网站解决了这个问题,但没有得到任何帮助。
响应告诉您您未通过身份验证。
因此,您的问题出在需要先进行的身份验证调用上。
实际上你没有传递linkedin guideline中提到的超过256的描述字段中的字符。
如需了解更多信息,请查看以下屏幕截图:
删除您的负载并添加此内容。
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\"}}"];
我集成了最新的sdksLinkedin分享内容。因为它以前是有效的,但现在它给出了错误。请找到以下错误消息。
Error Domain=LISDKErrorAPIDomain Code=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 的开发者门户网站解决了这个问题,但没有得到任何帮助。
响应告诉您您未通过身份验证。
因此,您的问题出在需要先进行的身份验证调用上。
实际上你没有传递linkedin guideline中提到的超过256的描述字段中的字符。
如需了解更多信息,请查看以下屏幕截图:
删除您的负载并添加此内容。
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\"}}"];