2012-10-09 63 views
0

我使用OAuthStarter工具包訪問LinkedIn API。我成功獲取權限的訪問令牌。無法使用LinkedIn的OAuth入門工具包共享

rw_ns
r_basicprofile
r_fullprofile

有可能獲取配置文件的詳細信息,以及分享僅意見和同時共享URL或圖片的說明等。我使用以下代碼:

-(void)postUpdate 
{ 
    NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"]; 
    OAMutableURLRequest *request = 
    [[OAMutableURLRequest alloc] initWithURL:url 
          consumer:[self getConsumer] 
           token:self.accesstoken 
          callback:nil 
        signatureProvider:nil]; 

    NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys: 

        [[NSDictionary alloc] 
        initWithObjectsAndKeys: 
        @"anyone",@"code",nil], @"visibility", 
        @"title goes here",@"title", 
        @"comment goes here", @"comment", 
        @"description goes here",@"description", 
        @"www.google.com",@"submitted-url", 
        @"http://economy.blog.ocregister.com/files/2009/01/linkedin-logo.jpg",@"submitted-image-url", 
        nil]; 
    [request setValue:@"json" forHTTPHeaderField:@"x-li-format"]; 
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; 

    NSString *updateString = [update 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:)]; 

    } 

但我得到一個錯誤的反應如下:

2012-10-09 18:27:29.906 SocialConnectTest[9460:19a03] data { 
"errorCode": 0, 
"message": "Invalid xml {Expected elements '[email protected]://api.linkedin.com/v1 [email protected]://api.linkedin.com/v1 [email protected]://api.linkedin.com/v1 [email protected]://api.linkedin.com/v1 [email protected]://api.linkedin.com/v1 [email protected]://api.linkedin.com/v1 [email protected]://api.linkedin.com/v1 [email protected]://api.linkedin.com/v1' instead of '[email protected]://api.linkedin.com/v1' here in element [email protected]://api.linkedin.com/v1}", 
"requestId": "W2G7WJDHOJ", 
"status": 400, 
"timestamp": 1349787449685 
} 

而且我不知道是什麼問題。任何人都可以幫我解決這個問題嗎?

+0

它看起來像端點期待XML,即使您指定JSON。您是否嘗試過推送XML以查看錯誤是否相同? –

回答

3

我修好了。 的問題是在後參數

  1. 爲每鏈接的API,如果我們在請求體使用JSON文件 然後post數據的密鑰必須在駝峯,而在XML 「 - 「使用分離的密鑰名稱
  2. 共享參數如submittedUrl,subsubmittedImageUrl,描述,標題**等。必須是名爲** content的密鑰值。

,所以我修改了代碼如下..

-(void)postUpdateHERE 
{ 
    NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"]; 
    OAMutableURLRequest *request = 
    [[OAMutableURLRequest alloc] initWithURL:url 
          consumer:[self getConsumer] 
           token:self.accesstoken 
          callback:nil 
        signatureProvider:nil]; 

    NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys: 

        [[NSDictionary alloc] 
        initWithObjectsAndKeys: 
        @"anyone",@"code",nil], @"visibility", 

        @"comment goes here", @"comment", 
        [[NSDictionary alloc] 
        initWithObjectsAndKeys: 
        @"description goes here",@"description", 
        @"www.google.com",@"submittedUrl", 
         @"title goes here",@"title", 
        @"http://economy.blog.ocregister.com/files/2009/01/linkedin-logo.jpg",@"submittedImageUrl",nil],@"content", 
        nil]; 
    [request setValue:@"json" forHTTPHeaderField:@"x-li-format"]; 
    [request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"]; 
    NSString *updateString = [update 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:)]; 

} 

現在的代碼工作對我來說..

+0

我試過了你的代碼,但它在OAuth Starter Kit項目上崩潰。你從哪裏打電話給你'postUpdateHERE'功能? – Martin

+0

這就是簡單的一個功能,可以調用事件發生時,你可以登錄,看看是什麼原因導致崩潰 –

+0

Aromal你能幫我解決這個問題嗎? http://stackoverflow.com/questions/20141897/error-like-unlike-and-comment-using-linkedin-rest-api-for-ios –