将URL重定向到iphone中的app for linkedIn [英] Redirecting Url to app in iphone for linkedIn

查看:104
本文介绍了将URL重定向到iphone中的app for linkedIn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iPhone授权LinkedIn ..

I am trying to authorize LinkedIn with iPhone..

我使用以下代码重定向网址

I am using following code to redirect url

NSString *authUrl = [NSString stringWithFormat:@"https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%@&scope=%@&state=%@&redirect_uri=%@" ,
                     API_KEY ,
                     @"r_fullprofile",
                     @"ASDKASIIWER23432KKQ",
                     @"http://www.myappname.com"
                     ];


[[UIApplication sharedApplication] openURL:[NSURL URLWithString: authUrl]];

在我的Url类型中,我已将URL Scheme添加为 http:// 和url标识符为

In my Url types, i have added URL Scheme as http:// and url identifier as

 www.myappname.com

但是在授权后,我没有从浏览器返回我的应用程序。

however after authorizing , i don't get back to my application from browser.

我错了任何想法?

推荐答案

我现在使用了diff方法,我在应用程序中使用了webView并正在使用它。到目前为止工作完美。

i have used a diff approach now, i have used webView inside app and is using it. Works perfect so far.

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.myWebView setDelegate:self];
    self.indicator = [[CustomActivityViewer alloc] initWithView:self.view];

    NSString *authUrl = [NSString stringWithFormat:@"https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=%@&scope=%@&state=%@&redirect_uri=%@" ,
                         API_KEY ,
                         @"r_fullprofile rw_nus r_emailaddress r_network w_messages",
                         SCOPE_CODE
                         REDIRECT_URI
                         ];
    authUrl = [authUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:authUrl]]];
}

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [self.indicator startAnimating];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self.indicator stopAnimating];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [self.indicator stopAnimating];
}

- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest: (NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType
{
    NSURL *url = request.URL;
    NSLog(@"%@", url.absoluteString);

    if ( [url.host isEqualToString:HOST])
    {
        URLParser *parser = [[URLParser alloc] initWithURLString:url.absoluteString];
        NSString *code = [parser valueForVariable:@"code"];

        if (code != nil)
        {
            NSString *authUrl = [NSString stringWithFormat:@"https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=%@&redirect_uri=%@&client_id=%@&client_secret=%@",
                                 code,
                                 REDIRECT_URI_OAUTH,
                                 API_KEY,
                                 SECRET_KEY];

            NSLog(@"%@" , authUrl);
            authUrl = [authUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

           [Utilities responseFromURL:[NSURL URLWithString:authUrl] completionBlock:^(NSString *response, NSError *err)
            {
                if (err != nil)
                {
                    [Utilities errorDisplay];
                }
                else
                {
                    NSDictionary *results = [response JSONValue];
                    [defaults setObject:[results objectForKey:@"access_token"] forKey:@"access_token"];
                }
           }];
        }
    }
    return YES;
}

这篇关于将URL重定向到iphone中的app for linkedIn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆