菜鸟教程小白 发表于 2022-12-12 09:32:44

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


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

<p><strong>当我点击 btn linkedIn 分享时这个方法..</strong></p>

<pre><code> - (void)linkedBtnEvent
    {
    if(oAuthLoginView != nil) {

      oAuthLoginView.delegate = nil;
      oAuthLoginView = nil;
    }

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

    [ addObserver:self
                                             selector:@selector(loginViewDidFinish:)
                                                 name:@&#34;loginViewDidFinish&#34;
                                             object:self.oAuthLoginView];

    ;
}
</code></pre>

<p><strong>这是登录后处理分享的方法..</strong></p>

<pre><code>-(void) loginViewDidFinish:(NSNotification*)notification
{
    [ removeObserver:self];

    ;
}

- (void)profileApiCall
{
    NSURL *url = ;
    OAMutableURLRequest *request =
    [ initWithURL:url
                                    consumer:oAuthLoginView.consumer
                                       token:oAuthLoginView.accessToken
                                    callback:nil
                           signatureProvider:nil];

    ;

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

}

- (void)profileApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
    NSString *responseBody = [ initWithData:data
                                                   encoding:NSUTF8StringEncoding];

    NSDictionary *profile = ;

    if ( profile )
    {
      NSLog(@&#34;%@&#34;, [ initWithFormat:@&#34;%@ %@&#34;,
                      , ]);
    }

    // The next thing we want to do is call the network updates
    ;
}

- (void)profileApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
    NSLog(@&#34;%@&#34;,);
}

- (void)networkApiCall
{
    NSURL *url = ;
    OAMutableURLRequest *request =
    [ initWithURL:url
                                    consumer:oAuthLoginView.consumer
                                       token:oAuthLoginView.accessToken
                                    callback:nil
                           signatureProvider:nil];

    ;

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

}

- (void)networkApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
    if (isSharedLinked)
    {
      NSLog(@&#34;Shared Successfully&#34;);
      linkedBtn.enabled = NO;
    }
    else
    {
      isSharedLinked = YES;
      ;
    }
}

- (void)networkApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
    NSLog(@&#34;%@&#34;,);
}

- (void)postTextLinkedIn
{   
    NSURL *url = ;
    OAMutableURLRequest *request =
    [ initWithURL:url
                                    consumer:oAuthLoginView.consumer
                                       token:oAuthLoginView.accessToken
                                    callback:nil
                           signatureProvider:nil];

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

    ;
    NSString *updateString = ;

    ;
    ;

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

- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data
{
    // The next thing we want to do is call the network updates
    ;
}

- (void)postUpdateApiCallResult:(OAServiceTicket *)ticket didFail:(NSData *)error
{
    NSLog(@&#34;%@&#34;,);
}
</code></pre>

<p>它没有显示任何错误,它总是在 LinkedIn 中成功分享,但没有文字分享..
请帮我解决这个问题...我不知道我犯了什么错误..</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您需要在“范围”中添加<strong>“rw_nus”</strong>。这仅允许应用程序共享更新...这是您的错误,否则您的所有代码都是正确的人..</p>

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

    ;   

    OARequestParameter *nameParam = [ initWithName:@&#34;scope&#34;
                                                                     value:@&#34;r_fullprofile+r_contactinfo+r_emailaddress+r_network+r_basicprofile+rw_nus&#34;];
    NSArray *params = ;
    ;
    OARequestParameter * scopeParameter=;

    ];

    OADataFetcher *fetcher = [[ init] autorelease];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(requestTokenResult:didFinish:)
                  didFailSelector:@selector(requestTokenResult:didFail:)];   
}
</code></pre>

<p>将其替换为您的 <strong>oAuthloginView.m</strong></p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Linkedin Share 在我的应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/23285468/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/23285468/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Linkedin Share 在我的应用程序中不起作用