0

ユーザーのプロフィール写真と、会社名、役職、業種、場所などのプロフィール フィールドを表示したい。ProfilePicCall を呼び出して、プロフィール写真を取得します。

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

    NSLog(@"the request is %@",request);


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

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

次に、画像ビューで写真を表示するには、以下のコードを使用します

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

    NSDictionary *profile = [responseBody objectFromJSONString];
    // [responseBody release];

    if ( profile )
    {
        NSLog(@"Profile is %@",profile);

   NSString *picture_url = [[NSUserDefaults standardUserDefaults]valueForKey:@"linkedid_Profile_url"];

        NSURL *imageurl = [NSURL URLWithString:picture_url];

        NSData *imagedata = [[NSData alloc]initWithContentsOfURL:imageurl];

        UIImage *image = [UIImage imageWithData: imagedata];
        [LinkedInPicture setImage:image];

     }
    else
    {
        NSDictionary *profile = [responseBody objectFromJSONString];
        NSLog(@"last path componemt is %@",profile);

    }
    // The next thing we want to do is call the network updates
    [self networkApiCall];
    [[NSUserDefaults standardUserDefaults] setValue:@"Used" forKey:@"linkedin"];

}

しかし、画像は画像ビューに表示されません。画像の表示方法とLinkedIn APIの使い方を教えてください

ありがとう。

4

2 に答える 2

5

私の質問に対する解決策を見つけました。LinkedIn API 呼び出しを次のように変更する必要があります。

- (void)profileApiCall
{

// NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~"];
     NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,picture-url,location:(name),positions:(company:(name),title),specialties,date-of-birth,interests,languages)"];

OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
                                consumer:oAuthLoginView.consumer
                                   token:oAuthLoginView.accessToken
                                callback:nil
                       signatureProvider:nil];

NSLog(@"the request is %@",request);


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

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


}

ありがとう。

于 2013-09-05T07:32:53.750 に答える
1

私は上記のアプローチが好きではありませんでした。

最初に、LinkedIn https://github.com/jeyben/IOSLinkedInAPIの Auth2.0 でログ プロセスを支援するこのライブラリを使用します。

次のように使用するか、ドキュメントを読んで自分でコードを変更してください。

解決策はこのリクエストhttps://api.linkedin.com/v1/people/~:(picture-url)?oauth2_access_token= &format=json です

LIALinkedInApplication *application = [LIALinkedInApplication applicationWithRedirectURL:@"http://www.ancientprogramming.com/liaexample"
                                                                                  clientId:@"clientId"
                                                                              clientSecret:@"clientSecret"
                                                                                     state:@"DCEEFWF45453sdffef424"
                                                                             grantedAccess:@[@"r_fullprofile", @"r_network"]];



LIALinkedInHttpClient *client = [LIALinkedInHttpClient clientForApplication:application presentingViewController:nil];

[client getAuthorizationCode:^(NSString *code) {
    [client getAccessToken:code success:^(NSDictionary *accessTokenData) {
      NSString *accessToken = [accessTokenData objectForKey:@"access_token"];
      //here you already have you access token
      //SOLUTION == https://api.linkedin.com/v1/people/~:(picture-url)?oauth2_access_token=<ACCESS_TOKEN>&format=json
      //make a http request and get the result with an image url

  } cancel:^{
    NSLog(@"Authorization was cancelled by user");
  } failure:^(NSError *error) {
    NSLog(@"Authorization failed %@", error);
  }];
}

私にとってはうまくいきます

于 2015-04-14T16:20:12.300 に答える