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

eyh26e7m  于 2023-01-27  发布在  iOS
关注(0)|答案(1)|浏览(174)

嗨,我需要从我的应用程序发送LinkedIn连接请求。我引用此链接,但我仍然得到错误。

  1. LinkedIn Integration in iOS: Invitation API not working
    我的代码
    • 按以下代码发送请求**
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];
    • OAD数据提取器. 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];
}

我在下面遇到错误

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

o授权登录视图. 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"];

这些是我给出的previlages。我分享文本和从LinkedIn获得个人资料信息,所有工作正常,但发送请求不工作。

xmjla07d

xmjla07d1#

像这样编辑
NSURL *url = [带有字符串的NSURL URL:@”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];

你只是混淆了这个。我只是在你的参考链接做了一些改变,它的工作原理就像这样使用。我希望它会对你有帮助。

相关问题