ios - Linked In invitation api using NSMutable request -
am using following code send invite linked in account using email id. problem turns out no invitation request received. please help...
-(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); } } }]; }
Comments
Post a Comment