登录时设置共享权限w_share
。
NSString *url = [NSString stringWithFormat:@".../oauth2/authorization?response_type=code&client_id=%@&redirect_uri=%@&state=svhgktyjuid&scope=r_basicprofile+r_emailaddress+w_share",linked_in_api_key,call_back_url];
- (void)shareImp
{
NSString *message = [NSString stringWithFormat:@"share This on Linkedin"];
NSMutableDictionary *contentDic=[[NSMutableDictionary alloc] init];
[contentDic setValue:logoURL forKey:@"submitted-image-url"];
[contentDic setValue:@"https://itunes.apple.com/..." forKey:@"submitted-url"];
[contentDic setValue:message forKey:@"title"];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
[[NSDictionary alloc]
initWithObjectsAndKeys:
@"anyone",@"code",nil], @"visibility",
[NSString stringWithFormat:@"I have a new APP! And I got it in a snap!"] ,@"comment",contentDic,@"content",nil];
NSString *updateString = [update JSONString];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=%@",_accessToken]];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest setValue:@"json" forHTTPHeaderField:@"x-li-format"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[urlRequest setHTTPBodyWithString:updateString];
[urlRequest setHTTPMethod:@"POST"];
//allocate a new operation queue
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
//Loads the data for a URL request and executes a handler block on an
//operation queue when the request completes or fails.
[NSURLConnection
sendAsynchronousRequest:urlRequest
queue:queue
completionHandler:^(NSURLResponse *response,
NSData *data,
NSError *error) {
NSLog(@"response...%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}];
}
谢谢。希望这会对你有帮助。