LinkedIn Integration in iOS: Invitation API not working

前端 未结 1 1342
渐次进展
渐次进展 2021-01-07 03:19

I\'m trying to integrate LinkedIn in my iOS application, where I need to Authenticate, then fetch profile details and post to LinkedIn from my app. I do all

相关标签:
1条回答
  • 2021-01-07 03:29

    Glad to inform all that after long 4 days of continuos research, I got this problem solved! I got the solution from this Linkedin thread

    You just need to make a few changes in the code:

    NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/mailbox"];
    
        OAMutableURLRequest *request =
        [[OAMutableURLRequest alloc] initWithURL:url
        consumer:oAuthLoginView.consumer
        token:oAuthLoginView.accessToken
        callback:nil
        signatureProvider:nil];
        [request setHTTPMethod:@"POST"];
        NSString *messageToPerson = @"/people/email=target@gmail.com";
        NSDictionary *person = [[NSDictionary alloc] initWithObjectsAndKeys:[[[NSDictionary alloc] initWithObjectsAndKeys:messageToPerson,@"_path",@"TargetFirstName",@"first-name",@"TargetSecondName",@"last-name",nil] autorelease], @"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] autorelease], @"invitation-request",nil];
        NSDictionary *ic = [[NSDictionary alloc] initWithObjectsAndKeys:ir,@"item-content", nil];
        NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:values,@"recipients",@"Invitation",@"subject",@"ConnectWithMe",@"body", ir, @"item-content", nil];
        [request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        NSLog(@"%@",[update description]);
        NSString *updateString = [update JSONString];
    
        [request prepare];
    
        [request setHTTPBodyWithString:updateString];
    
        OADataFetcher *fetcher = [[OADataFetcher alloc] init];
        [fetcher fetchDataWithRequest:request delegate:self
        didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)
        didFailSelector:@selector(postUpdateApiCallResult:didFail:) withId:1];
    
        [request release];
    

    and in oAdata OADataFetcher.m

    - (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector  withId:(int)idtm
    {
    
    [request release];
    
    request = [aRequest retain];
    
    delegate = aDelegate;
    
    didFinishSelector = finishSelector;
    
    didFailSelector = failSelector;
    
    //note this change
    
    if (idtm!=1) {
       
    [request prepare];
    
           }
    
    connection = [[NSURLConnection alloc] initWithRequest:aRequest delegate:self];
    
    }
    
    

    Try this. Will work for sure. Hope this will help future visitors.

    Regards

    0 讨论(0)
提交回复
热议问题