How to post an image to a LinkedIn account using Objective-C code on iOS?

后端 未结 2 789
悲&欢浪女
悲&欢浪女 2020-12-10 10:33

I am able to post the comment to LinkedIn but not able to post the image. This is the code for posting the comment:

  NSURL *url = [NSURL URLWit         


        
相关标签:
2条回答
  • 2020-12-10 11:01

    try this bellow code may be its help you:-

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

    i found this from bellow stackover flow answer:-

    Can't share using OAuth Starter Kit for LinkedIn

    EDIT:-

    For TamilKing comment reply. you can get image URL of you currunt Location using Google API. First you need to get you currunt Location Image Like:-

    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
    

    That given you current Location image for example:-

    enter image description here

    Now you have to convert this above NSString to NSURL like

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

    and use this url that you want to share in to LinkedIn. hope that helps you.

    0 讨论(0)
  • 2020-12-10 11:03

    You may need to do more, but for sure you'll need to set the length...

    [request setValue:[NSString stringWithFormat:@"%d", updateString.length] forHTTPHeaderField:@"Content-Length"];
    
    0 讨论(0)
提交回复
热议问题