2012-11-16 22 views
1

我能发布到LinkedIn的评论,但无法发布image。这是发表评论的代码:如何在iOS上使用Objective-C代码将图像发布到LinkedIn帐户?

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

试试这个娄代码可能是它帮助你: -

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

} 

,我发现这个从波纹管stackover流回答: -

Can't share using OAuth Starter Kit for LinkedIn

编辑: -

对于TamilKing评论回复。您可以使用Google API获取currunt Location的图片网址。首先,你需要让你currunt地点图片喜欢: -

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 

,鉴于你目前的位置的图像,例如: -

enter image description here

现在你要转换这个上面的NSString NSURL像

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

并使用你想分享到LinkedIn的这个URL。希望能帮助你。

+0

@NitinGohel请帮我换LinkedIn。 –

+0

@Nitin Gohel:在此代码中,您使用submittedUrl表示我们需要在任何地方提交图像。我需要在LinkedIn上分享我的本地图片,可以帮助我吗? – TamilKing

+0

@TamilKing检查我的更新答案 –

3

你可能需要做更多,但是可以肯定,你将需要设置长度...

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