Oauth消费者 - LinkedIN更新状态

时间:2010-08-31 12:40:43

标签: iphone oauth linkedin

我尝试开发一个使用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

1 个答案:

答案 0 :(得分:2)

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

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];