簡體   English   中英

在iPhone中使用linkedin API檢索連接時收到錯誤

[英]getting error when retrieving connections using linkedin api in iphone

我有一個將我的Linkedin集成到我的應用程序中的應用程序。我想獲取已登錄用戶的連接。為此,我完成了代碼,但返回錯誤:

{
  "errorCode": 0,
  "message": "Unknown authentication scheme",
  "requestId": "98TKWP0T23",
  "status": 401,
  "timestamp": 1355726431107
}

這是我完成的代碼:

(NSMutableArray*) getFriendsList
{      
  NSString *url1 = [NSString stringWithFormat:@"http://api.linkedin.com/v1/people/id=%@:(connections)?format=application/json",linkedinid];
  NSLog(@"%@",url1);
  NSURL *url = [NSURL URLWithString:url1];

  OAMutableURLRequest *request = [[OAMutableURLRequest alloc] 
                                         initWithURL:url
                                            consumer:consumer
                                               token:token
                                            callback:nil
                                            signatureProvider:nil];
  [request setValue:@"json" forHTTPHeaderField:@"x-li-format"];
  [request setHTTPMethod:@"POST"];

   NSError *err;
   NSURLResponse *resp;
   NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:&resp error:&err];
   NSMutableArray *arr = [[NSMutableArray alloc] init];

   if (response != nil)
   {
     NSString *stringResponse = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
     SBJSON *parser = [[SBJSON alloc] init];
     NSDictionary *linkedin_response = [parser objectWithString:stringResponse error:nil];   
   }    
}

但在stringresponse中,它返回上述錯誤。

嘗試這個 :

- (void)getFriendsList
{
   NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/connections"];
   OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url
                                consumer:oAuthLoginView.consumer
                                   token:oAuthLoginView.accessToken
                                callback:nil
                       signatureProvider:nil];

   [request setValue:@"json" forHTTPHeaderField:@"x-li-format"];

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

- (void)networkApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
   NSString *responseBody = [[NSString alloc] initWithData:data
                                               encoding:NSUTF8StringEncoding]; 
   NSDictionary *demo = [responseBody objectFromJSONString];


   NSMutableArray *connections = [[NSMutableArray alloc] init];

   for(int i=0;i<[[demo objectForKey:@"_count"] intValue];i++)
   {
      NSDictionary *person = [NSString stringWithFormat:@"%@ %@",[[[[responseBody objectFromJSONString] 
                                                                  objectForKey:@"values"] 
                                                                 objectAtIndex:i]
                                                                objectForKey:@"firstName"],[[[[responseBody objectFromJSONString] 
                                                                                              objectForKey:@"values"] 
                                                                                             objectAtIndex:i]
                                                                                            objectForKey:@"lastName"]];
      NSLog(@"Connection %d : %@",i,[NSString stringWithFormat:@"%@ %@",[[[[responseBody objectFromJSONString] 
                                                                         objectForKey:@"values"] 
                                                                        objectAtIndex:i]
                                                                       objectForKey:@"firstName"],[[[[responseBody objectFromJSONString] 
                                                                                                     objectForKey:@"values"] 
                                                                                                    objectAtIndex:i]
                                                                                                   objectForKey:@"lastName"]]);
     [connections addObject:person];  
   }
}

- (void)networkApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error 
{
   NSLog(@"%@",[error description]);
}

從表面上看,您沒有在帖子中傳遞“用戶名/密碼”,因此,您正在獲得“未知身份驗證方案”。 我不確定您是否能夠在自己的應用程序中檢測到已登錄用戶的連接,除非您將其憑據存儲在應用程序中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM