1

LinkedInにコメントを投稿することはできますが、投稿することはできませんimage。コメントを投稿するためのコードは次のとおりです。

  NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"];
  OAMutableURLRequest *request = 
        [[OAMutableURLRequest alloc] initWithURL:url
                                        consumer:self.consumer
                                           token:self.accessToken
                                        callback:nil
                               signatureProvider:nil];
  NSString *postedStr = self.textView.text;
  NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
                                [[NSDictionary alloc] 
                                 initWithObjectsAndKeys:
                                 @"anyone",@"code",nil], @"visibility", 
                                postedStr, @"comment", nil];
  [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:)];    
    // [self.view addSubview:linkedinView];
   [request release];

どんな提案も本当にありがたいです!

4

2 に答える 2

4

この以下のコードを試してみてください。

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

}

私は以下のスタックオーバーフローの答えからこれを見つけました:-

LinkedIn用のOAuthスターターキットを使用して共有することはできません

編集:-

TamilKingコメント返信用。Google APIを使用して、現在の場所の画像URLを取得できます。まず、次のような現在の場所の画像を取得する必要があります:-

NSString *staticMapUrl = [NSString stringWithFormat:@"http://maps.google.com/maps/api/staticmap?markers=color:red|%f,%f&%@&sensor=true",lat, log,@"zoom=12&size=114x116"];    //That above staticMapURl NSlog is :http://maps.google.com/maps/api/staticmap?markers=color:red|1.282130,103.803131&zoom=12&size=114x116&sensor=true

たとえば、現在の場所の画像が表示されます。-

ここに画像の説明を入力してください

次に、上記のNSStringを次のようにNSURLに変換する必要があります。

NSURL *mapUrl = [NSURL URLWithString:[staticMapUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

LinkedInに共有するこのURLを使用します。それがあなたを助けることを願っています。

于 2012-11-16T05:35:05.883 に答える
3

もっとやる必要があるかもしれませんが、確かに長さを設定する必要があります...

[request setValue:[NSString stringWithFormat:@"%d", updateString.length] forHTTPHeaderField:@"Content-Length"];
于 2012-11-16T05:41:13.763 に答える