0

アプリにリンクインを統合しているアプリケーションがあります。ログインしているユーザーの接続を取得したいのですが、このためにコードを実行しましたが、エラーが返されます:

{
  "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 では、上記のエラーが返されます。

4

2 に答える 2

4

これを試して :

- (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]);
}
于 2012-12-17T07:38:41.907 に答える
0

見た目からすると、投稿で「ユーザー名/パスワード」を渡していないため、「不明な認証スキーム」を取得しています。アプリ内にユーザーの資格情報を保存していない限り、ログインしているユーザーの接続を自分のアプリで検出できるかどうかはわかりません。

于 2012-12-17T06:53:00.630 に答える