1

我已经编写了将内容发布到linkedIn 墙上的代码,如果我从更新字典中删除内容字典,它工作正常。请参阅以下包含发布数据的代码:

- (IBAction)postUpdate
    {
     NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"];
     OAMutableURLRequest *request =
     [[OAMutableURLRequest alloc] initWithURL:url
                                     consumer:oAuthLoginView.consumer
                                        token:oAuthLoginView.accessToken
                                     callback:nil
                            signatureProvider:nil];

     NSDictionary *content=[[NSDictionary alloc] initWithObjectsAndKeys:@"http://www.celebs101.com/wallpapers/Bruce_Lee/421101/Bruce_Lee_Wallpaper.jpg",@"submitted-image-url",@"http://www.youtube.com/watch?v=GoZ2Be2zLq8",@"submitted-url",@"Post Image and Video testing",@"title",@"Posted Description",@"description",nil];

     NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
                             [[NSDictionary alloc]
                              initWithObjectsAndKeys:
                              @"anyone",@"code",nil], @"visibility",
                             @"Test posting to linkedIn", @"comment",content,@"content",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:)];
    }

发布数据来自 didfinishSelector 是:

发布后的数据是:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <error>
      <status>401</status>
      <timestamp>1356601471318</timestamp>
      <request-id>MFW58DCKE9</request-id>
      <error-code>0</error-code>
      <message>[unauthorized]. OAU:0onill9cburx|3c05c306-aad8-4d07-a2a1-2430aa21b54a|*01|*01:1356601465:Ji7pimMqrXp3RHCNJLv8iKZsklk=</message>
    </error>

我不知道为什么会这样?请帮忙..在此先感谢..

4

2 回答 2

0

我已经解决了

在LinkedIn上发布的工作代码如下:

- (IBAction)postUpdate
{
 NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~/shares"];
 OAMutableURLRequest *request =
 [[OAMutableURLRequest alloc] initWithURL:url
                                 consumer:oAuthLoginView.consumer
                                    token:oAuthLoginView.accessToken
                                 callback:nil
                        signatureProvider:nil];

 NSMutableDictionary *contentDic=[[NSMutableDictionary alloc] init];

 [contentDic setValue:@"http://www.celebs101.com/wallpapers/Bruce_Lee/421101/Bruce_Lee_Wallpaper.jpg" forKey:@"submitted-image-url"];
 [contentDic setValue:@"http://www.linkedin.com" forKey:@"submitted-url"];
 [contentDic setValue:[NSString stringWithFormat:@"A title for your share"] forKey:@"title"];


 NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
                         [[NSDictionary alloc]
                          initWithObjectsAndKeys:
                          @"anyone",@"code",nil], @"visibility",
                         @"Test posting to linkedIn",@"comment",contentDic,@"content",nil];

 [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

 NSString *updateString = [update JSONString];


 NSLog(@"json string is %@",updateString);

 [request setHTTPBodyWithString:updateString];
 [request setHTTPMethod:@"POST"];

 OADataFetcher *fetcher = [[OADataFetcher alloc] init];

 [fetcher fetchDataWithRequest:request
                      delegate:self
             didFinishSelector:@selector(postUpdateApiCallResult:didFinish:)
               didFailSelector:@selector(postUpdateApiCallResult:didFail:)];
}


- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
 NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
 NSLog(@"data after posting is %@",myString);
}


- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
 NSLog(@"%@",[error description]);
}
于 2012-12-27T11:00:41.017 回答
0

如果您收到此类错误:

在此处输入图像描述

所以这可能是因为“submitted-url”键中的post url。因此,一种简单的方法是首先使用此链接( http://tinyurl.com/api-create.php?url=post_url)使“submitted-url”的 post_url 变短。然后将这个简短的 post_url 用于“submitted-url”值。这可以解决您的问题。

有时,“submitted-url”键的长 url 会导致这种问题。

于 2013-04-25T08:39:50.667 回答