2012-05-07 77 views
3

我正在關注此鏈接:https://github.com/yahoo/yos-social-objc以檢索雅虎聯繫人。獲取iphone中的雅虎聯繫人

提供所有憑據(即密鑰,消費者密鑰,應用程序ID)後,它將瀏覽器登錄。但登錄後,它顯示此消息:

要完成雅虎共享!信息與xxxx,輸入代碼xxxx到xxxx

所以,我沒有得到,我應該輸入此代碼?它將如何重定向到我的應用程序。

任何幫助將不勝感激。

+0

你知道嗎? – Kamilski81

回答

0

CloudSponge爲其聯繫進口商提供了一個iOS部件。通過iOS設備訪問our test drive page,瞭解它是如何工作的。

我爲CloudSponge工作,如果您有任何問題,請讓我知道。

+0

謝謝@Jay,我發現你的應用程序可以工作,但你怎麼做額外的窗口,那裏幕後發生了什麼? – Kamilski81

0

您需要指定回調網址。默認情況下它是「oob」,並會給你驗證碼。如果您通過webview代理呈現自己的Web視圖並監視驗證者代碼,那將會更好。這是你如何做到的。

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; 
    } 
} 
+1

嗨@AdityaSinha,你有沒有成功地與雅虎合作。我想獲取雅虎用戶的聯繫人。第一次應用程序崩潰。當我下次嘗試時。該應用程序正在工作,雅虎聯繫人也提取。但我想找出與雅虎sdk有什麼問題。如果可能,請提供完整的代碼。 –

+1

我也困惑'ApplicationId'參數。初始化'YOSSession'時應用程序id的價值是什麼。 –

+0

也請提供callbackurl的知識。我瞭解,回調網址用於應用重定向。那就是我們將在.plist中寫入。像myApp://但是當我們在YDN中創建新應用程序時,這是要求回調URL(如Facebook),並且不接受任何不是從http或https開始的字符串。 –

相關問題