简体   繁体   English

如何在iOS上使用Objective-C代码将图像发布到LinkedIn帐户?

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

I am able to post the comment to LinkedIn but not able to post the image . 我可以将评论发布到LinkedIn,但不能发布image This is the code for posting the comment: 这是发布评论的代码:

  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];

Any suggestion really appreciated! 任何建议都非常感谢!

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:- 我从波纹管stackover流答案中找到了这个:-

Can't share using OAuth Starter Kit for LinkedIn 无法使用针对LinkedIn的OAuth入门工具包进行共享

EDIT:- 编辑:-

For TamilKing comment reply. 对于TamilKing评论回复。 you can get image URL of you currunt Location using Google API. 您可以使用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:- 这给了您当前的位置图片,例如:

在此处输入图片说明

Now you have to convert this above NSString to NSURL like 现在您必须将上面的NSString转换为NSURL,例如

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

and use this url that you want to share in to LinkedIn. 并使用您要分享到LinkedIn的URL。 hope that helps you. 希望对您有帮助。

您可能需要做更多的事情,但是可以肯定的是,您需要设置长度...

[request setValue:[NSString stringWithFormat:@"%d", updateString.length] forHTTPHeaderField:@"Content-Length"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM