0

我尝试开发一个使用 OauthConsumer 与 LinkedIN 连接的应用程序。一切正常,我可以提取用户数据,但是当我想更新用户状态时,我的状态错误 401 带有消息 [未授权]。我有访问令牌,这是代码:

NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/current-status"];
OAMutableURLRequest *request1 = [[OAMutableURLRequest alloc] initWithURL:url
                 consumer:consumer
                    token:accToken// 
                    realm:nil   // 
                 signatureProvider:nil] ; // 
NSLog(@"mytoken%@",[request1 token]);

[request1 setHTTPMethod:@"PUT"];

[request1 setHTTPBodyWithString:@"<?xml version=''1.0'' encoding=''UTF-8'?><current-status>is setting their status using the LinkedIn API.</current-status>"]; 

OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request1
    delegate:self
    didFinishSelector:@selector(status:didFinishWithData:)
    didFailSelector:@selector(status:didFailWithError:)];

有任何想法吗???请帮帮我!!!!!!:( tnx

4

1 回答 1

2

好的,正确的代码是下一个:

NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"];
OAMutableURLRequest *request1 = [[OAMutableURLRequest alloc] initWithURL:url
                                                                consumer:consumer
                                                                   token:accToken
                                                                   realm:nil
                                                       signatureProvider:nil];  
NSLog(@"mytoken%@",[request1 token]);




[request1 setHTTPShouldHandleCookies:NO];
[request1 setValue:@"text/xml;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];

[request1 setHTTPMethod:@"POST"];
[request1 prepare];
[request1 setHTTPBody:[NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/status.xml", [[ NSBundle mainBundle] resourcePath]]]];


NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request1 delegate:self];
[connection start];
于 2010-09-09T07:49:17.060 回答