• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - Linkedin Share 在我的应用程序中不起作用

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:32:44 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

您好,我想通过我的应用在 LinkedIn 中分享文本。我的代码在下面...

当我点击 btn linkedIn 分享时这个方法..

 - (void)linkedBtnEvent
    {
    if(oAuthLoginView != nil) {

        oAuthLoginView.delegate = nil;
        oAuthLoginView = nil;
    }

    oAuthLoginView = [[OAuthLoginView alloc] initWithNibName:nil bundle:nil];
    oAuthLoginView.delegate=self;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selectorselector(loginViewDidFinish
                                                 name"loginViewDidFinish"
                                               object:self.oAuthLoginView];

    [self presentViewController:self.oAuthLoginView animated:YES completion:nil];
}

这是登录后处理分享的方法..

-(void) loginViewDidFinishNSNotification*)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    [self profileApiCall];
}

- (void)profileApiCall
{
    NSURL *url = [NSURL URLWithString"https://api.linkedin.com/v1/people/~"];
    OAMutableURLRequest *request = 
    [[OAMutableURLRequest alloc] initWithURL:url
                                    consumerAuthLoginView.consumer
                                       tokenAuthLoginView.accessToken
                                    callback:nil
                           signatureProvider:nil];

    [request setValue"json" forHTTPHeaderField"x-li-format"];

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelectorselector(profileApiCallResult:didFinish
                  didFailSelectorselector(profileApiCallResult:didFail];    

}

- (void)profileApiCallResultOAServiceTicket *)ticket didFinishNSData *)data 
{
    NSString *responseBody = [[NSString alloc] initWithData:data
                                                   encoding:NSUTF8StringEncoding];

    NSDictionary *profile = [responseBody objectFromJSONString];

    if ( profile )
    {
        NSLog(@"%@", [[NSString alloc] initWithFormat"%@ %@",
                      [profile objectForKey"firstName"], [profile objectForKey"lastName"]]);
    }

    // The next thing we want to do is call the network updates
    [self networkApiCall];
}

- (void)profileApiCallResultOAServiceTicket *)ticket didFailNSData *)error 
{
    NSLog(@"%@",[error description]);
}

- (void)networkApiCall
{
    NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/network/updates?scope=self&count=1&type=STAT"];
    OAMutableURLRequest *request = 
    [[OAMutableURLRequest alloc] initWithURL:url
                                    consumerAuthLoginView.consumer
                                       tokenAuthLoginView.accessToken
                                    callback:nil
                           signatureProvider:nil];

    [request setValue:@"json" forHTTPHeaderField:@"x-li-format"];

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(networkApiCallResult:didFinish
                  didFailSelector:@selector(networkApiCallResult:didFail];    

}

- (void)networkApiCallResultOAServiceTicket *)ticket didFinishNSData *)data 
{
    if (isSharedLinked)
    {
        NSLog(@"Shared Successfully");
        linkedBtn.enabled = NO;
    }
    else
    {
        isSharedLinked = YES;
        [self performSelector:@selector(postTextLinkedIn) withObject:nil afterDelay:1];
    }
}

- (void)networkApiCallResultOAServiceTicket *)ticket didFailNSData *)error 
{
    NSLog(@"%@",[error description]);
}

- (void)postTextLinkedIn
{    
    NSURL *url = [NSURL URLWithString:@"https://api.linkedin.com/v1/people/~/shares"];
    OAMutableURLRequest *request = 
    [[OAMutableURLRequest alloc] initWithURL:url
                                    consumerAuthLoginView.consumer
                                       tokenAuthLoginView.accessToken
                                    callback:nil
                           signatureProvider:nil];

    NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:
                            [[NSDictionary alloc] 
                             initWithObjectsAndKeys:
                             @"anyone",@"code",nil], @"visibility", 
                            @"Wow its working... Share the text in Linked In", @"comment", nil];

    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    NSString *updateString = [update JSONString];

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

    OADataFetcher *fetcher = [[OADataFetcher alloc] init];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(postUpdateApiCallResult:didFinish
                  didFailSelector:@selector(postUpdateApiCallResult:didFail];    
}

- (void)postUpdateApiCallResultOAServiceTicket *)ticket didFinish:(NSData *)data 
{
    // The next thing we want to do is call the network updates
    [self networkApiCall];
}

- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error 
{
    NSLog(@"%@",[error description]);
}

它没有显示任何错误,它总是在 LinkedIn 中成功分享,但没有文字分享.. 请帮我解决这个问题...我不知道我犯了什么错误..



Best Answer-推荐答案


您需要在“范围”中添加“rw_nus”。这仅允许应用程序共享更新...这是您的错误,否则您的所有代码都是正确的人..

- (void)requestTokenFromProvider
{
    OAMutableURLRequest *request = 
            [[[OAMutableURLRequest alloc] initWithURL:requestTokenURL
                                             consumer:self.consumer
                                                token:nil   
                                             callback:linkedInCallbackURL
                                    signatureProvider:nil] autorelease];

    [request setHTTPMethod:@"OST"];   

    OARequestParameter *nameParam = [[OARequestParameter alloc] initWithName:@"scope"
                                                                       value:@"r_fullprofile+r_contactinfo+r_emailaddress+r_network+r_basicprofile+rw_nus"];
    NSArray *params = [NSArray arrayWithObjects:nameParam, nil];
    [request setParameters:params];
    OARequestParameter * scopeParameter=[OARequestParameter requestParameter:@"scope" value:@"r_fullprofile r_contactinfo r_emailaddress r_network r_fullprofile rw_nus"];

    [request setParameters:[NSArray arrayWithObject:scopeParameter]];

    OADataFetcher *fetcher = [[[OADataFetcher alloc] init] autorelease];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(requestTokenResult:didFinish
                  didFailSelector:@selector(requestTokenResult:didFail];    
}

将其替换为您的 oAuthloginView.m

关于ios - Linkedin Share 在我的应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23285468/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap