【问题标题】:LinkedIn starter kit not sharing content to wall If add content dictionary?LinkedIn 入门工具包未将内容共享到墙上 如果添加内容字典?
【发布时间】:2012-12-27 08:50:55
【问题描述】:

我已经编写了将内容发布到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>

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

【问题讨论】:

  • 在“postUpdateApiCallResult:didFail:”方法中有没有报错?
  • postUpdateApiCallResult:didFinish: 调用
  • 我不知道这是否是问题,但是 api 文档在这里说:developer.linkedin.com/documents/api-requests-json 如果你想使用 json 格式,你应该将 x-li-format 标头设置为 json
  • 有或选项 x-li-format: json or Content-type: application/json
  • or 选项在哪里?我可以读到:您需要在 JSON 帖子上将 Content-Type 设置为 application/json,并将“x-li-format”标头设置为“json”。我的母语不是英语,但“as well as”应该表示“and”而不是“or”。我错了吗?

标签: iphone xcode ios5 linkedin


【解决方案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];

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

【讨论】:

  • 对不起,目前我没有任何虚拟代码。当时我发布此内容时有。并且创建新代码需要一些时间。
  • 我收到此错误 'OAuthStarterKit[577:11303] *** 由于未捕获的异常 'NSRangeException' 导致应用程序终止,原因:'*** -[__NSArrayI objectAtIndex:]:索引 1 超出范围 [ 0 .. 0]'请帮帮我。
  • 它们是一些空数组,其中任何代码都在搞乱。只需阅读流程并检查。
  • 这次不可能了兄弟,这几天很忙抱歉。
  • 如果可能的话帮帮我先生,我对你的期望更高,我必须重播我的老板,所以如果可能的话回复我,否则没关系。谢谢
【解决方案2】:

如果您遇到此类错误:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-30
    • 2019-07-02
    • 1970-01-01
    • 2015-05-28
    • 1970-01-01
    • 1970-01-01
    • 2013-11-20
    • 2015-08-22
    相关资源
    最近更新 更多