使用以下代码使用电子邮件ID将邀请发送到帐户中的另一个链接。问题是事实证明没有收到邀请请求。请帮忙......
-(void)sendInviteTo:(NSDictionary*) member WithCompletionHandler:(void (^)(BOOL, NSError *))completionBlock
{
GlobalHandler *gb=[GlobalHandler getObject];
[gb.tokenHandler linkedinAuthTokenWithCompletionHandler:^(NSString *authToken, NSError *error)
{
if(!error)
{
NSString *firstName=[member valueForKey:@"firstName"];
NSString *lastName=[member valueForKey:@"lastName"];
NSString *str=[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=%@&format=json",authToken];
NSLog(@"invite str=%@",str);
NSMutableURLRequest *request=[NSMutableURLRequest
requestWithURL:[NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:4.0];
NSString *messageToPerson = [NSString stringWithFormat:@"/people/email=%@",[member valueForKey:@"emailId"]];
NSDictionary *person = [[NSDictionary alloc] initWithObjectsAndKeys:[[NSDictionary alloc] initWithObjectsAndKeys:messageToPerson,@"_path",firstName,@"first-name",lastName,@"last-name",nil], @"person",nil];
NSArray *valueArray = [[NSArray alloc] initWithObjects:person,nil];
NSDictionary *values = [[NSDictionary alloc] initWithObjectsAndKeys:valueArray,@"values", nil];
NSDictionary *ir = [[NSDictionary alloc] initWithObjectsAndKeys:[[NSDictionary alloc] initWithObjectsAndKeys:@"friend",@"connect-type",nil], @"invitation-request",nil];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:values,@"recipients",@"Invitation",@"subject",@"ConnectWithMe",@"body", ir, @"item-content", nil];
NSError *error2;
NSLog(@"%@",update);
NSData *postData = [NSJSONSerialization dataWithJSONObject:update options:0 error:&error2];
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:postData options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@",dict);
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *error=nil;
NSData *connection=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(!error)
{
NSError *error1;
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:connection options:NSJSONReadingAllowFragments error:&error1];
NSLog(@"%@",dict);
completionBlock(YES,nil);
}
else
{
completionBlock(NO,error);
}
}
}];
}