【问题标题】:IOS 7 LinkedIn share button implementation using oauth2.0 share issueIOS 7 LinkedIn分享按钮实现使用oauth2.0分享问题
【发布时间】:2026-01-22 15:35:01
【问题描述】:

我正在尝试制作一个与 LinkedIn 共享内容的简单应用程序, 在这里,我可以毫无错误地收到结果,但内容不在我的 LinkedIn 时间线中。任何帮助将不胜感激,这是我的代码。

-(void)JsonPostRequst:(NSData *)jsonRequestData{

Globaltoken  *token_Obj=[Globaltoken  getInstance];

NSString* shareUrl=[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=%@",token_Obj.token];

NSURL *url = [NSURL URLWithString:shareUrl];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60];

[request setHTTPMethod:@"POST"];

[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

[request setValue:@"x-li-format" forHTTPHeaderField:@"json"];

[request setValue:[NSString stringWithFormat:@"%d", [jsonRequestData length]] forHTTPHeaderField:@"Content-Length"];

[request setHTTPBody: jsonRequestData];

NSError *errorReturned = nil;

NSURLResponse *response =nil;

NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&errorReturned];

if (errorReturned==nil){

    NSLog(@"data =%@",result);

}else{

    NSLog(@"error =%@",errorReturned);

}

}

-(IBAction)linkedInShare:(id)sender {

NSDictionary *json = [[NSDictionary alloc] initWithObjectsAndKeys:

                        [[NSDictionary alloc]

                         initWithObjectsAndKeys:

                         @"anyone",@"code",nil], @"visibility",

    [[NSDictionary alloc]

                         initWithObjectsAndKeys:

                         @"title",@"title",

@"description",@"Description",

@"submitted-url",@"www.google.com",

@"submitted-image-url",@"http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png",

nil], @"content",

                        @"comment", @"comment", nil];



if ([NSJSONSerialization isValidJSONObject:json]) {

   NSError *error=nil;

   NSData *jsonData=[NSJSONSerialization dataWithJSONObject:json options:NSJSONWritingPrettyPrinted error:&error];

    if (error==nil && jsonData !=nil) {

        [self JsonPostRequst:jsonData];

    }

}

}

【问题讨论】:

  • 我已经使用 xml 而不是 json 解决了这个问题。如果有人需要帮助,请告诉我
  • 您能用您的 XML 解决方案回答这个问题吗?

标签: ios oauth-2.0 http-post linkedin


【解决方案1】:

Oauth 共享工具包对我有用,我刚刚解决了我的问题。确保我们正在测试的设备设置了正确的时间,因为提前 5 分钟的时间戳是由linkedin API 授予的

【讨论】: