3

我正在关注此链接:https ://github.com/yahoo/yos-social-objc用于检索雅虎联系人。

提供所有凭据(即密钥、消费者密钥、应用程序 ID)后,它将进入浏览器进行登录。但登录后,它显示此消息:

完成yahoo的分享!带有 xxxx 的信息,在 xxxx 中输入代码 xxxx

那么,我没有得到我应该输入此代码的地方?以及它将如何重定向到我的应用程序。

任何帮助将不胜感激。

4

2 回答 2

0

CloudSponge为其联系人导入器提供了一个 iOS 小部件。从您的 iOS 设备访问我们的试驾页面,了解它是如何工作的。

我为 CloudSponge 工作,如果您有任何问题,请告诉我。

于 2012-10-12T06:45:08.780 回答
0

您需要指定回调 url。默认情况下它是“oob”并且会给你验证码。如果您展示自己的 web 视图并通过 webview 委托监控验证程序代码会更好。这是你如何做到的。

YOSSession *yahooSession; //instance variable

- (IBAction)yahooButtonAction:(UIButton *)sender {

    yahooSession = [YOSSession sessionWithConsumerKey:YAHOO_CONSUMER_KEY
                                           andConsumerSecret:YAHOO_CONSUMER_SECRET
                                            andApplicationId:YAHOO_APP_ID];

    // try to resume a user session if one exists
    BOOL hasSession = [yahooSession resumeSession];

    if(hasSession == FALSE) {
        [self fetchSession];
    }else{
        [self sendRequests];
    }
}

-(void)fetchSession{

    // create a new YOSAuthRequest used to fetch OAuth tokens.
    YOSAuthRequest *tokenAuthRequest = [YOSAuthRequest requestWithSession:yahooSession];

    // fetch a new request token from oauth.
    YOSRequestToken *newRequestToken = [tokenAuthRequest fetchRequestTokenWithCallbackUrl:@"http://localhost"];

    // if it looks like we have a valid request token
    if(newRequestToken && newRequestToken.key && newRequestToken.secret) {
        // store the request token for later use
        [yahooSession setRequestToken:newRequestToken];
        [yahooSession saveSession];

        // create an authorization URL for the request token
        NSURL *authorizationUrl = [tokenAuthRequest authUrlForRequestToken:yahooSession.requestToken];
        [self presentWebViewForYahooWithAuthURL:authorizationUrl];
        //present it in webview

    } else {
        // NSLog(@"error fetching request token. check your consumer key and secret.");
    }
}

-(void) presentWebViewForYahooWithAuthURL:(NSURL *)url{

    _yahooWebView = [[UIWebView alloc] initWithFrame:self.view.frame];
    _yahooWebView.delegate=self; //so that we can observe the url for verifier
    [_yahooWebView loadRequest:[NSURLRequest requestWithURL:url]];
    [self.view addSubview:_yahooWebView];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

    NSString *requestString = request.URL.absoluteString;
    if ([requestString rangeOfString:@"http://localhost"].length>0) {
        NSRange verifierRange = [requestString rangeOfString:@"oauth_verifier="];
        if (verifierRange.length>0) {

            verifierRange.location =verifierRange.location+verifierRange.length;
            verifierRange.length = requestString.length-verifierRange.location;
            NSLog(@"Verifier => %@", [requestString substringWithRange:verifierRange]);
            yahooSession.verifier=[requestString substringWithRange:verifierRange];
            [self sendRequests];
        }
        return NO;
    }
    else{
        return YES;
    }
}
于 2014-01-03T12:29:18.617 回答