Oauth Consumer - LinkedIN 更新状态

发布于 2024-09-16 20:33:04 字数 981 浏览 5 评论 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

I try to develop a app that use OauthConsumer for connection with LinkedIN.
All work fine, I can extract the user data but when I want to update User status I've status error 401 with message [unauthorized].
I've the access token, this is the code:

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

Any ideas??? Plese help me!!!!!! :(
tnx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴情 2024-09-23 20:33:04

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

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

OK, the rigth code is the next:

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文