2012-11-16 20 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"]; 
相關問題