iphone - 领英邀请API错误401[未授权]-iPhone sdk

标签 iphone ios ios5 ios4 linkedin

我正在使用 OAuth-Sample-Client 代码通过链接邀请 API 从电子邮件地址发送邀请。 我已经创建了与开发者网站中描述的相同的主体,但现在我收到 401 错误,我已经搜索了很多,但没有从任何网站或论坛得到任何让我摆脱它的解决方案。 我的回复如下。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
  <status>401</status>
  <timestamp>1351159386437</timestamp>
  <request-id>YX4NRU3S7J</request-id>
  <error-code>0</error-code>
  <message>[unauthorized]. OAU:ron8e8nko3te|e0a96317-dfdc-44fb-b427-5655e02f97ed|*01|*01:1351159294:dRCDN6b3K9F/mwWAaByKZQPgeVw=</message>
</error>

这里我的 json 字符串是这样的:

{"body":"Say yes!","subject":"Invitation to connect.","recipients":{"values":[{"person":{"first-name":"test","last-name":"test","_path":"/people/email=test@test.com"}}]},"item-content":{"invitation-request":{"connect-type":"friend"}}}

我已经使用下面的代码发送邀请。

- (IBAction)postButton_TouchUp:(UIButton *)sender
{    
    [statusTextView resignFirstResponder];
    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",@"test",@"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];
    NSLog(@"%@",[dict description]);
    NSString *updateString = [dict JSONString];
    [request setHTTPBodyWithString:updateString];
    [request setHTTPMethod:@"POST"];

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)
                  didFailSelector:@selector(postUpdateApiCallResult:didFail:)];    
    [request release];
}

我现在卡住了,请让我离开这里。 -提前致谢

最佳答案

手动调用OADataFetcher的prepare方法。只需将其放在设置请求正文之前即可。

[request prepare];
[request setHTTPBodyWithString:updateString];

这对我有用。 当您使用 Invitation API 时,还要从 OADataFetcher 中删除 prepare 方法。

关于iphone - 领英邀请API错误401[未授权]-iPhone sdk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13066297/

相关文章:

iphone - 将 Dicom 图像转换为 jpg,png

iphone - Cordova - 内部超链接始终在 Safari 中打开

ios - 从 map 注释标注的过渡

iphone - NSFileManager removeItemAtPath 锁定主线程

ios - 模态视图 Controller 从自定义单元格选择问题中分离 - iOS 7

ios - 当我尝试导入它时,为什么它说找不到我的类(class),而它显然在侧边栏中?

iphone - 拖动图像时如何改变alpha值

iphone - 获取当前歌曲的插图时出错

iphone - 可以在应用程序中禁用 Siri 吗?

c++ - 未知类型名称 'class' ;你的意思是 'Class' 吗?