我正在尝试在LinkedIn中分享一些内容。我正在获取用户个人资料,但我无法使用此代码分享帖子:
[self.client GET:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~:(id,picture-url,email-address,first-name,last-name,headline,location,industry,positions,educations)?oauth2_access_token=%@&format=json", accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result) {
NSLog(@"current user %@", result);
[self.client POST:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~/shares/?comment=test&title=commentTest&oauth2_access_token=%@&format=json",accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *result) {
NSLog(@"result share %@",result);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failed to post %@", error);
}];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"failed to fetch current user %@", error);
}];
我已经阅读了这篇文档文章https://developer.linkedin.com/documents/writing-linkedin-apis,但我不理解的是,他们是否意味着我们在请求中发布了一个完整的json或xml?如果是这样,你有解决方案吗?
答案 0 :(得分:0)
尝试将 Content-Type 和 Accept 添加到http标头。
AFJSONRequestSerializer *requestSerializer = [AFJSONRequestSerializer serializer];
[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
self.client.requestSerializer = requestSerializer;