简体   繁体   English

使用IOS中的api在linkedin用户中发送连接请求

[英]Send connection request in linkedin users using api in IOS

Hi I need to send connection request in linkedIn from my app. 嗨,我需要从我的应用程序在linkedIn中发送连接请求。 I refer this link but still I getting error. 我引用了此链接,但仍然出现错误。

1. LinkedIn Integration in iOS: Invitation API not working 1. iOS中的LinkedIn集成:邀请API无效

My code 我的密码

To send request by below 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:[[OAHMAC_SHA1SignatureProvider alloc] init]];


    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    NSDictionary *temp=[[NSDictionary alloc]initWithObjectsAndKeys:@"/people/email=test@test.com",@"_path",@"Test",@"first-name",@"Testing",@"last-name", nil];
    NSDictionary *temp2=[[NSDictionary alloc] initWithObjectsAndKeys:temp,@"person",nil];
    NSArray *arr2=[[NSArray alloc]initWithObjects:temp2, nil];
    NSDictionary *value=[[NSDictionary alloc]initWithObjectsAndKeys:arr2,@"values", nil];
    NSDictionary *dict3=[[NSDictionary alloc]initWithObjectsAndKeys:@"friend",@"connect-type",nil];
    NSDictionary *dict4=[[NSDictionary alloc] initWithObjectsAndKeys:dict3,@"invitation-request", nil];
    NSDictionary *dict=[[NSDictionary alloc]initWithObjectsAndKeys:dict4,@"item-content",@"Say yes!",@"body",@"Invitation to connect.",@"subject",value,@"recipients", nil];

    NSString *updateString = [dict JSONString];
    [request setHTTPBodyWithString:updateString];
    [request setHTTPMethod:@"POST"];

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(postUpdateApiCallResult1:didFinish:)
                  didFailSelector:@selector(postUpdateApiCallResult1:didFail:) withPrepare:NO];

OADataFetcher.m OADataFetcher.m

- (void)fetchDataWithRequest:(OAMutableURLRequest *)aRequest delegate:(id)aDelegate didFinishSelector:(SEL)finishSelector didFailSelector:(SEL)failSelector withPrepare:(BOOL)isPrepare
{
    [request release];
    request = [aRequest retain];
    delegate = aDelegate;
    didFinishSelector = finishSelector;
    didFailSelector = failSelector;

    if (isPrepare)
        [request prepare];

    connection = [[NSURLConnection alloc] initWithRequest:aRequest delegate:self];
}

I getting error below 我在下面出现错误

<error>
  <status>401</status>
  <timestamp>1399885201227</timestamp>
  <request-id>YTU5250BQI</request-id>
  <error-code>0</error-code>
  <message>Unknown authentication scheme</message>
</error>

oAuthLoginView.m oAuthLoginView.m

OARequestParameter *nameParam = [[OARequestParameter alloc] initWithName:@"scope"
                                                                       value:@"r_fullprofile+r_contactinfo+r_emailaddress+r_network+rw_nus+w_messages"];
    NSArray *params = [NSArray arrayWithObjects:nameParam, nil];
    [request setParameters:params];
    OARequestParameter * scopeParameter=[OARequestParameter requestParameter:@"scope" value:@"r_fullprofile r_contactinfo r_emailaddress r_network rw_nus w_messages"];

These are the previlages I gave. 这些是我给的特权。 I sharing text and get profile information from linkedIn all working fine but send request not working.... 我共享文本并从LinkedIn获取个人资料信息,但一切正常,但发送请求无效。

Edit like this 像这样编辑

NSURL *url = [NSURL URLWithString:@" http://api.linkedin.com/v1/people/~/mailbox "]; 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=test@test.com";
NSDictionary *person = [[NSDictionary alloc] initWithObjectsAndKeys:[[NSDictionary alloc] initWithObjectsAndKeys:messageToPerson,@"_path",@"Testing",@"first-name",@"Test",@"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];
[request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

NSString *updateString = [update JSONString];

[request prepare];

[request setHTTPBodyWithString:updateString];

OADataFetcher *fetcher = [[OADataFetcher alloc] init];

[fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(postUpdateApiCallResult1:didFinish:)
                  didFailSelector:@selector(postUpdateApiCallResult1:didFail:) withPrepare:NO];

You just confuse this. 您只是对此感到困惑。 I just make changes in your reference link it works just use like this. 我只是在您的参考链接中进行更改,它的工作原理如下。 I hope it will helpful to you.. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM