如何使用iOS上的Objective-C代码将图像发布到LinkedIn帐户? [英] How to post an image to a LinkedIn account using Objective-C code on iOS?

查看:115
本文介绍了如何使用iOS上的Objective-C代码将图像发布到LinkedIn帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将评论发布到LinkedIn,但无法发布图片。这是发布评论的代码:

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

任何建议真的很感激!

推荐答案

试试这个以下代码可能会帮助你: -

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

}

我从bellow stackover flow回答: -

i found this from bellow stackover flow answer:-

不能使用OAuth Starter Kit for LinkedIn分享

编辑: -

对于 TamilKing 评论回复。您可以使用Google API获取您的图片网址。首先,你需要让你成为currunt位置图像像: -

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:-

现在你必须转换这上面NSString到NSURL喜欢

Now you have to convert this above NSString to NSURL like

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

并使用您想要分享到LinkedIn的这个网址。希望对你有帮助。

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

这篇关于如何使用iOS上的Objective-C代码将图像发布到LinkedIn帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆